Ejemplo n.º 1
0
        static tmInc manualTimeInc(string manualformat)
        {
            tmInc second = tmInc.second;

            if ((manualformat == null) || (manualformat.Length == 0))
            {
                return(second);
            }
            int index = manualformat.IndexOf('f');

            if (index < 0)
            {
                if (manualformat.IndexOf('s') >= 0)
                {
                    return(tmInc.second);
                }
                if (manualformat.IndexOf('m') >= 0)
                {
                    return(tmInc.minute);
                }
                if (manualformat.IndexOfAny(new char[] { 'h', 'H' }) >= 0)
                {
                    return(tmInc.hour);
                }
                if (manualformat.IndexOf('d') >= 0)
                {
                    return(tmInc.day);
                }
                if (manualformat.IndexOf('M') >= 0)
                {
                    return(tmInc.month);
                }
                if (manualformat.IndexOf('y') >= 0)
                {
                    second = tmInc.year;
                }
                return(second);
            }
            int num2 = -1;

            if ((index > 0) && manualformat.Substring(index - 1, 1).Equals((char)'%'))
            {
                num2 = -1;
            }
            else
            {
                for (int i = 1; i < 6; i++)
                {
                    if (((index + i) >= manualformat.Length) || (manualformat.Substring(index + i, 1) != "f"))
                    {
                        break;
                    }
                    num2--;
                }
            }
            return((tmInc)num2);
        }
Ejemplo n.º 2
0
        static TimeSpan TimeSpanFromTmInc(tmInc ti)
        {
            TimeSpan span = TimeSpan.FromSeconds(1.0);

            if (ti.Equals(tmInc.maxtime))
            {
                return(span);
            }
            if (ti.CompareTo(tmInc.tickf1) > 0)
            {
                return(TimeSpan.FromSeconds((double)ti));
            }
            int  num   = (int)ti;
            long ticks = 1L;

            for (num += 7; num > 0; num--)
            {
                ticks *= 10L;
            }
            return(new TimeSpan(ticks));
        }
Ejemplo n.º 3
0
        public static TimeSpan NiceTimeSpan(TimeSpan ts, string manualformat)
        {
            tmInc second = tmInc.second;

            if (!string.IsNullOrEmpty(manualformat))
            {
                second = manualTimeInc(manualformat);
            }
            long ticks = 0L;
            long num2  = 0L;

            if ((second < tmInc.second) && (ts.TotalSeconds < 10.0))
            {
                ticks = ts.Ticks;
                num2  = TimeSpanFromTmInc(second).Ticks;
                while (ticks > (10L * num2))
                {
                    num2 *= 10L;
                }
                long num3 = num2;
                if (ticks > num3)
                {
                    num3 *= 2L;
                }
                if (ticks > num3)
                {
                    num3 = 5L * num2;
                }
                if (ticks > num3)
                {
                    num3 = 10L * num2;
                }
                return(TimeSpan.FromTicks(num3));
            }
            ticks = (long)Math.Ceiling(ts.TotalSeconds);
            if (ticks == 0L)
            {
                return(TimeSpanFromTmInc(second));
            }
            num2 = 1L;
            if (second < tmInc.minute)
            {
                if (ticks < 60L)
                {
                    num2 = getNiceInc(new int[] { 1, 2, 5, 10, 15, 30 }, ticks, (long)second);
                    if (num2 != 0L)
                    {
                        return(TimeSpan.FromSeconds((double)num2));
                    }
                }
                second = tmInc.minute;
            }
            if (second < tmInc.hour)
            {
                if (ticks < 0xe10L)
                {
                    num2 = getNiceInc(new int[] { 1, 2, 5, 10, 15, 30 }, ticks, (long)second);
                    if (num2 != 0L)
                    {
                        return(TimeSpan.FromSeconds((double)num2));
                    }
                }
                second = tmInc.hour;
            }
            if (second < tmInc.day)
            {
                if (ticks < 0x15180L)
                {
                    num2 = getNiceInc(new int[] { 1, 3, 6, 12 }, ticks, (long)second);
                    if (num2 != 0L)
                    {
                        return(TimeSpan.FromSeconds((double)num2));
                    }
                }
                second = tmInc.day;
            }
            if (second < tmInc.month)
            {
                if (ticks < 0x28de80L)
                {
                    num2 = getNiceInc(new int[] { 1, 2, 7, 14 }, ticks, (long)second);
                    if (num2 != 0L)
                    {
                        return(TimeSpan.FromSeconds((double)num2));
                    }
                }
                second = tmInc.month;
            }
            if (second < tmInc.year)
            {
                if (ticks < 0x1e13380L)
                {
                    num2 = getNiceInc(new int[] { 1, 2, 3, 4, 6 }, ticks, (long)second);
                    if (num2 != 0L)
                    {
                        return(TimeSpan.FromSeconds((double)num2));
                    }
                }
                second = tmInc.year;
            }
            num2 = 0xbbf81e00L;
            if (ticks < num2)
            {
                num2 = getNiceInc(new int[] { 1, 2, 5, 10, 20, 50 }, ticks, (long)second);
                if (num2 == 0L)
                {
                    num2 = 0xbbf81e00L;
                }
            }
            return(TimeSpan.FromSeconds((double)num2));
        }