Exemplo n.º 1
0
        // Token: 0x060030CE RID: 12494 RVA: 0x000BA4CC File Offset: 0x000B86CC
        private static string FormatStandard(TimeSpan value, bool isInvariant, string format, TimeSpanFormat.Pattern pattern)
        {
            StringBuilder stringBuilder = StringBuilderCache.Acquire(16);
            int           num           = (int)(value._ticks / 864000000000L);
            long          num2          = value._ticks % 864000000000L;

            if (value._ticks < 0L)
            {
                num  = -num;
                num2 = -num2;
            }
            int n    = (int)(num2 / 36000000000L % 24L);
            int n2   = (int)(num2 / 600000000L % 60L);
            int n3   = (int)(num2 / 10000000L % 60L);
            int num3 = (int)(num2 % 10000000L);

            TimeSpanFormat.FormatLiterals formatLiterals;
            if (isInvariant)
            {
                if (value._ticks < 0L)
                {
                    formatLiterals = TimeSpanFormat.NegativeInvariantFormatLiterals;
                }
                else
                {
                    formatLiterals = TimeSpanFormat.PositiveInvariantFormatLiterals;
                }
            }
            else
            {
                formatLiterals = default(TimeSpanFormat.FormatLiterals);
                formatLiterals.Init(format, pattern == TimeSpanFormat.Pattern.Full);
            }
            if (num3 != 0)
            {
                num3 = (int)((long)num3 / (long)Math.Pow(10.0, (double)(7 - formatLiterals.ff)));
            }
            stringBuilder.Append(formatLiterals.Start);
            if (pattern == TimeSpanFormat.Pattern.Full || num != 0)
            {
                stringBuilder.Append(num);
                stringBuilder.Append(formatLiterals.DayHourSep);
            }
            stringBuilder.Append(TimeSpanFormat.IntToString(n, formatLiterals.hh));
            stringBuilder.Append(formatLiterals.HourMinuteSep);
            stringBuilder.Append(TimeSpanFormat.IntToString(n2, formatLiterals.mm));
            stringBuilder.Append(formatLiterals.MinuteSecondSep);
            stringBuilder.Append(TimeSpanFormat.IntToString(n3, formatLiterals.ss));
            if (!isInvariant && pattern == TimeSpanFormat.Pattern.Minimum)
            {
                int num4 = formatLiterals.ff;
                while (num4 > 0 && num3 % 10 == 0)
                {
                    num3 /= 10;
                    num4--;
                }
                if (num4 > 0)
                {
                    stringBuilder.Append(formatLiterals.SecondFractionSep);
                    stringBuilder.Append(num3.ToString(DateTimeFormat.fixedNumberFormats[num4 - 1], CultureInfo.InvariantCulture));
                }
            }
            else if (pattern == TimeSpanFormat.Pattern.Full || num3 != 0)
            {
                stringBuilder.Append(formatLiterals.SecondFractionSep);
                stringBuilder.Append(TimeSpanFormat.IntToString(num3, formatLiterals.ff));
            }
            stringBuilder.Append(formatLiterals.End);
            return(StringBuilderCache.GetStringAndRelease(stringBuilder));
        }
Exemplo n.º 2
0
        private static string FormatStandard(TimeSpan value, bool isInvariant, string format, TimeSpanFormat.Pattern pattern)
        {
            StringBuilder sb   = StringBuilderCache.Acquire(16);
            int           num1 = (int)(value._ticks / 864000000000L);
            long          num2 = value._ticks % 864000000000L;

            if (value._ticks < 0L)
            {
                num1 = -num1;
                num2 = -num2;
            }
            int n1 = (int)(num2 / 36000000000L % 24L);
            int n2 = (int)(num2 / 600000000L % 60L);
            int n3 = (int)(num2 / 10000000L % 60L);
            int n4 = (int)(num2 % 10000000L);

            TimeSpanFormat.FormatLiterals formatLiterals;
            if (isInvariant)
            {
                formatLiterals = value._ticks >= 0L ? TimeSpanFormat.PositiveInvariantFormatLiterals : TimeSpanFormat.NegativeInvariantFormatLiterals;
            }
            else
            {
                formatLiterals = new TimeSpanFormat.FormatLiterals();
                formatLiterals.Init(format, pattern == TimeSpanFormat.Pattern.Full);
            }
            if (n4 != 0)
            {
                n4 = (int)((long)n4 / (long)Math.Pow(10.0, (double)(7 - formatLiterals.ff)));
            }
            sb.Append(formatLiterals.Start);
            if (pattern == TimeSpanFormat.Pattern.Full || num1 != 0)
            {
                sb.Append(num1);
                sb.Append(formatLiterals.DayHourSep);
            }
            sb.Append(TimeSpanFormat.IntToString(n1, formatLiterals.hh));
            sb.Append(formatLiterals.HourMinuteSep);
            sb.Append(TimeSpanFormat.IntToString(n2, formatLiterals.mm));
            sb.Append(formatLiterals.MinuteSecondSep);
            sb.Append(TimeSpanFormat.IntToString(n3, formatLiterals.ss));
            if (!isInvariant && pattern == TimeSpanFormat.Pattern.Minimum)
            {
                int num3;
                for (num3 = formatLiterals.ff; num3 > 0 && n4 % 10 == 0; --num3)
                {
                    n4 /= 10;
                }
                if (num3 > 0)
                {
                    sb.Append(formatLiterals.SecondFractionSep);
                    sb.Append(n4.ToString(DateTimeFormat.fixedNumberFormats[num3 - 1], (IFormatProvider)CultureInfo.InvariantCulture));
                }
            }
            else if (pattern == TimeSpanFormat.Pattern.Full || n4 != 0)
            {
                sb.Append(formatLiterals.SecondFractionSep);
                sb.Append(TimeSpanFormat.IntToString(n4, formatLiterals.ff));
            }
            sb.Append(formatLiterals.End);
            return(StringBuilderCache.GetStringAndRelease(sb));
        }