// // FormatStandard // // Actions: Format the TimeSpan instance using the specified format. // private static String FormatStandard(TimeSpan value, bool isInvariant, String format, Pattern pattern) { StringBuilder sb = StringBuilderCache.Acquire(); int day = (int)(value._ticks / TimeSpan.TicksPerDay); long time = value._ticks % TimeSpan.TicksPerDay; if (value._ticks < 0) { day = -day; time = -time; } int hours = (int)(time / TimeSpan.TicksPerHour % 24); int minutes = (int)(time / TimeSpan.TicksPerMinute % 60); int seconds = (int)(time / TimeSpan.TicksPerSecond % 60); int fraction = (int)(time % TimeSpan.TicksPerSecond); FormatLiterals literal; if (isInvariant) { if (value._ticks < 0) { literal = NegativeInvariantFormatLiterals; } else { literal = PositiveInvariantFormatLiterals; } } else { literal = new FormatLiterals(); literal.Init(format, pattern == Pattern.Full); } if (fraction != 0) { // truncate the partial second to the specified length fraction = (int)((long)fraction / (long)Math.Pow(10, DateTimeFormat.MaxSecondsFractionDigits - literal.ff)); } // Pattern.Full: [-]dd.hh:mm:ss.fffffff // Pattern.Minimum: [-][d.]hh:mm:ss[.fffffff] sb.Append(literal.Start); // [-] if (pattern == Pattern.Full || day != 0) { // sb.Append(day); // [dd] sb.Append(literal.DayHourSep); // [.] } // sb.Append(IntToString(hours, literal.hh)); // hh sb.Append(literal.HourMinuteSep); // : sb.Append(IntToString(minutes, literal.mm)); // mm sb.Append(literal.MinuteSecondSep); // : sb.Append(IntToString(seconds, literal.ss)); // ss if (!isInvariant && pattern == Pattern.Minimum) { int effectiveDigits = literal.ff; while (effectiveDigits > 0) { if (fraction % 10 == 0) { fraction = fraction / 10; effectiveDigits--; } else { break; } } if (effectiveDigits > 0) { sb.Append(literal.SecondFractionSep); // [.FFFFFFF] sb.Append((fraction).ToString(DateTimeFormat.fixedNumberFormats[effectiveDigits - 1], CultureInfo.InvariantCulture)); } } else if (pattern == Pattern.Full || fraction != 0) { sb.Append(literal.SecondFractionSep); // [.] sb.Append(IntToString(fraction, literal.ff)); // [fffffff] } // sb.Append(literal.End); // return(StringBuilderCache.GetStringAndRelease(sb)); }
// // FormatStandard // // Actions: Format the TimeSpan instance using the specified format. // private static String FormatStandard(TimeSpan value, bool isInvariant, String format, Pattern pattern) { StringBuilder sb = StringBuilderCache.Acquire(); int day = (int)(value._ticks / TimeSpan.TicksPerDay); long time = value._ticks % TimeSpan.TicksPerDay; if (value._ticks < 0) { day = -day; time = -time; } int hours = (int)(time / TimeSpan.TicksPerHour % 24); int minutes = (int)(time / TimeSpan.TicksPerMinute % 60); int seconds = (int)(time / TimeSpan.TicksPerSecond % 60); int fraction = (int)(time % TimeSpan.TicksPerSecond); FormatLiterals literal; if (isInvariant) { if (value._ticks < 0) literal = NegativeInvariantFormatLiterals; else literal = PositiveInvariantFormatLiterals; } else { literal = new FormatLiterals(); literal.Init(format, pattern == Pattern.Full); } if (fraction != 0) { // truncate the partial second to the specified length fraction = (int)((long)fraction / (long)Math.Pow(10, DateTimeFormat.MaxSecondsFractionDigits - literal.ff)); } // Pattern.Full: [-]dd.hh:mm:ss.fffffff // Pattern.Minimum: [-][d.]hh:mm:ss[.fffffff] sb.Append(literal.Start); // [-] if (pattern == Pattern.Full || day != 0) { // sb.Append(day); // [dd] sb.Append(literal.DayHourSep); // [.] } // sb.Append(IntToString(hours, literal.hh)); // hh sb.Append(literal.HourMinuteSep); // : sb.Append(IntToString(minutes, literal.mm)); // mm sb.Append(literal.MinuteSecondSep); // : sb.Append(IntToString(seconds, literal.ss)); // ss if (!isInvariant && pattern == Pattern.Minimum) { int effectiveDigits = literal.ff; while (effectiveDigits > 0) { if (fraction % 10 == 0) { fraction = fraction / 10; effectiveDigits--; } else { break; } } if (effectiveDigits > 0) { sb.Append(literal.SecondFractionSep); // [.FFFFFFF] sb.Append((fraction).ToString(DateTimeFormat.fixedNumberFormats[effectiveDigits - 1], CultureInfo.InvariantCulture)); } } else if (pattern == Pattern.Full || fraction != 0) { sb.Append(literal.SecondFractionSep); // [.] sb.Append(IntToString(fraction, literal.ff)); // [fffffff] } // sb.Append(literal.End); // return StringBuilderCache.GetStringAndRelease(sb); }
private static string FormatStandard(TimeSpan value, bool isInvariant, string format, Pattern pattern) { FormatLiterals negativeInvariantFormatLiterals; StringBuilder builder = new StringBuilder(); int num = (int) (value._ticks / 0xc92a69c000L); long num2 = value._ticks % 0xc92a69c000L; if (value._ticks < 0L) { num = -num; num2 = -num2; } int n = (int) ((num2 / 0x861c46800L) % 0x18L); int num4 = (int) ((num2 / 0x23c34600L) % 60L); int num5 = (int) ((num2 / 0x989680L) % 60L); int num6 = (int) (num2 % 0x989680L); if (isInvariant) { if (value._ticks < 0L) { negativeInvariantFormatLiterals = NegativeInvariantFormatLiterals; } else { negativeInvariantFormatLiterals = PositiveInvariantFormatLiterals; } } else { negativeInvariantFormatLiterals = new FormatLiterals(); negativeInvariantFormatLiterals.Init(format, pattern == Pattern.Full); } if (num6 != 0) { num6 = (int) (((long) num6) / ((long) Math.Pow(10.0, (double) (7 - negativeInvariantFormatLiterals.ff)))); } builder.Append(negativeInvariantFormatLiterals.Start); if ((pattern == Pattern.Full) || (num != 0)) { builder.Append(num); builder.Append(negativeInvariantFormatLiterals.DayHourSep); } builder.Append(IntToString(n, negativeInvariantFormatLiterals.hh)); builder.Append(negativeInvariantFormatLiterals.HourMinuteSep); builder.Append(IntToString(num4, negativeInvariantFormatLiterals.mm)); builder.Append(negativeInvariantFormatLiterals.MinuteSecondSep); builder.Append(IntToString(num5, negativeInvariantFormatLiterals.ss)); if (isInvariant || (pattern != Pattern.Minimum)) { if ((pattern == Pattern.Full) || (num6 != 0)) { builder.Append(negativeInvariantFormatLiterals.SecondFractionSep); builder.Append(IntToString(num6, negativeInvariantFormatLiterals.ff)); } } else { int ff = negativeInvariantFormatLiterals.ff; while (ff > 0) { if ((num6 % 10) != 0) { break; } num6 /= 10; ff--; } if (ff > 0) { builder.Append(negativeInvariantFormatLiterals.SecondFractionSep); builder.Append(num6.ToString(DateTimeFormat.fixedNumberFormats[ff - 1], CultureInfo.InvariantCulture)); } } builder.Append(negativeInvariantFormatLiterals.End); return builder.ToString(); }
/// <summary>Format the TimeSpan instance using the specified format.</summary> private static StringBuilder FormatStandard(TimeSpan value, bool isInvariant, string format, Pattern pattern) { StringBuilder sb = StringBuilderCache.Acquire(InternalGlobalizationHelper.StringBuilderDefaultCapacity); int day = (int)(value.Ticks / TimeSpan.TicksPerDay); long time = value.Ticks % TimeSpan.TicksPerDay; if (value.Ticks < 0) { day = -day; time = -time; } int hours = (int)(time / TimeSpan.TicksPerHour % 24); int minutes = (int)(time / TimeSpan.TicksPerMinute % 60); int seconds = (int)(time / TimeSpan.TicksPerSecond % 60); int fraction = (int)(time % TimeSpan.TicksPerSecond); FormatLiterals literal; if (isInvariant) { literal = value.Ticks < 0 ? NegativeInvariantFormatLiterals : PositiveInvariantFormatLiterals; } else { literal = new FormatLiterals(); literal.Init(format, pattern == Pattern.Full); } if (fraction != 0) { // truncate the partial second to the specified length fraction = (int)(fraction / TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - literal.ff)); } // Pattern.Full: [-]dd.hh:mm:ss.fffffff // Pattern.Minimum: [-][d.]hh:mm:ss[.fffffff] sb.Append(literal.Start); // [-] if (pattern == Pattern.Full || day != 0) { sb.Append(day); // [dd] sb.Append(literal.DayHourSep); // [.] } // AppendNonNegativeInt32(sb, hours, literal.hh); // hh sb.Append(literal.HourMinuteSep); // : AppendNonNegativeInt32(sb, minutes, literal.mm); // mm sb.Append(literal.MinuteSecondSep); // : AppendNonNegativeInt32(sb, seconds, literal.ss); // ss if (!isInvariant && pattern == Pattern.Minimum) { int effectiveDigits = literal.ff; while (effectiveDigits > 0) { if (fraction % 10 == 0) { fraction = fraction / 10; effectiveDigits--; } else { break; } } if (effectiveDigits > 0) { sb.Append(literal.SecondFractionSep); // [.FFFFFFF] sb.Append((fraction).ToString(DateTimeFormat.fixedNumberFormats[effectiveDigits - 1], CultureInfo.InvariantCulture)); } } else if (pattern == Pattern.Full || fraction != 0) { sb.Append(literal.SecondFractionSep); // [.] AppendNonNegativeInt32(sb, fraction, literal.ff); // [fffffff] } sb.Append(literal.End); return(sb); }
private static string FormatStandard(TimeSpan value, bool isInvariant, string format, Pattern pattern) { FormatLiterals negativeInvariantFormatLiterals; StringBuilder builder = new StringBuilder(); int num = (int)(value._ticks / 0xc92a69c000L); long num2 = value._ticks % 0xc92a69c000L; if (value._ticks < 0L) { num = -num; num2 = -num2; } int n = (int)((num2 / 0x861c46800L) % 0x18L); int num4 = (int)((num2 / 0x23c34600L) % 60L); int num5 = (int)((num2 / 0x989680L) % 60L); int num6 = (int)(num2 % 0x989680L); if (isInvariant) { if (value._ticks < 0L) { negativeInvariantFormatLiterals = NegativeInvariantFormatLiterals; } else { negativeInvariantFormatLiterals = PositiveInvariantFormatLiterals; } } else { negativeInvariantFormatLiterals = new FormatLiterals(); negativeInvariantFormatLiterals.Init(format, pattern == Pattern.Full); } if (num6 != 0) { num6 = (int)(((long)num6) / ((long)Math.Pow(10.0, (double)(7 - negativeInvariantFormatLiterals.ff)))); } builder.Append(negativeInvariantFormatLiterals.Start); if ((pattern == Pattern.Full) || (num != 0)) { builder.Append(num); builder.Append(negativeInvariantFormatLiterals.DayHourSep); } builder.Append(IntToString(n, negativeInvariantFormatLiterals.hh)); builder.Append(negativeInvariantFormatLiterals.HourMinuteSep); builder.Append(IntToString(num4, negativeInvariantFormatLiterals.mm)); builder.Append(negativeInvariantFormatLiterals.MinuteSecondSep); builder.Append(IntToString(num5, negativeInvariantFormatLiterals.ss)); if (isInvariant || (pattern != Pattern.Minimum)) { if ((pattern == Pattern.Full) || (num6 != 0)) { builder.Append(negativeInvariantFormatLiterals.SecondFractionSep); builder.Append(IntToString(num6, negativeInvariantFormatLiterals.ff)); } } else { int ff = negativeInvariantFormatLiterals.ff; while (ff > 0) { if ((num6 % 10) != 0) { break; } num6 /= 10; ff--; } if (ff > 0) { builder.Append(negativeInvariantFormatLiterals.SecondFractionSep); builder.Append(num6.ToString(DateTimeFormat.fixedNumberFormats[ff - 1], CultureInfo.InvariantCulture)); } } builder.Append(negativeInvariantFormatLiterals.End); return(builder.ToString()); }