// Token: 0x060015E6 RID: 5606 RVA: 0x00040744 File Offset: 0x0003E944 private static string FormatCustomized(DateTime dateTime, string format, DateTimeFormatInfo dtfi, TimeSpan offset) { Calendar calendar = dtfi.Calendar; StringBuilder stringBuilder = StringBuilderCache.Acquire(16); bool flag = calendar.ID == 8; bool flag2 = calendar.ID == 3; bool timeOnly = true; int i = 0; while (i < format.Length) { char c = format[i]; int num2; if (c <= 'K') { if (c <= '/') { if (c <= '%') { if (c != '"') { if (c != '%') { goto IL_64F; } int num = DateTimeFormat.ParseNextChar(format, i); if (num >= 0 && num != 37) { stringBuilder.Append(DateTimeFormat.FormatCustomized(dateTime, ((char)num).ToString(), dtfi, offset)); num2 = 2; goto IL_65B; } throw new FormatException(Environment.GetResourceString("Format_InvalidString")); } } else if (c != '\'') { if (c != '/') { goto IL_64F; } stringBuilder.Append(dtfi.DateSeparator); num2 = 1; goto IL_65B; } StringBuilder stringBuilder2 = new StringBuilder(); num2 = DateTimeFormat.ParseQuoteString(format, i, stringBuilder2); stringBuilder.Append(stringBuilder2); } else if (c <= 'F') { if (c != ':') { if (c != 'F') { goto IL_64F; } goto IL_1E3; } else { stringBuilder.Append(dtfi.TimeSeparator); num2 = 1; } } else if (c != 'H') { if (c != 'K') { goto IL_64F; } num2 = 1; DateTimeFormat.FormatCustomizedRoundripTimeZone(dateTime, offset, stringBuilder); } else { num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); DateTimeFormat.FormatDigits(stringBuilder, dateTime.Hour, num2); } } else if (c <= 'm') { if (c <= '\\') { if (c != 'M') { if (c != '\\') { goto IL_64F; } int num = DateTimeFormat.ParseNextChar(format, i); if (num < 0) { throw new FormatException(Environment.GetResourceString("Format_InvalidString")); } stringBuilder.Append((char)num); num2 = 2; } else { num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); int month = calendar.GetMonth(dateTime); if (num2 <= 2) { if (flag) { DateTimeFormat.HebrewFormatDigits(stringBuilder, month); } else { DateTimeFormat.FormatDigits(stringBuilder, month, num2); } } else if (flag) { stringBuilder.Append(DateTimeFormat.FormatHebrewMonthName(dateTime, month, num2, dtfi)); } else if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != DateTimeFormatFlags.None && num2 >= 4) { stringBuilder.Append(dtfi.internalGetMonthName(month, DateTimeFormat.IsUseGenitiveForm(format, i, num2, 'd') ? MonthNameStyles.Genitive : MonthNameStyles.Regular, false)); } else { stringBuilder.Append(DateTimeFormat.FormatMonth(month, num2, dtfi)); } timeOnly = false; } } else { switch (c) { case 'd': num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); if (num2 <= 2) { int dayOfMonth = calendar.GetDayOfMonth(dateTime); if (flag) { DateTimeFormat.HebrewFormatDigits(stringBuilder, dayOfMonth); } else { DateTimeFormat.FormatDigits(stringBuilder, dayOfMonth, num2); } } else { int dayOfWeek = (int)calendar.GetDayOfWeek(dateTime); stringBuilder.Append(DateTimeFormat.FormatDayOfWeek(dayOfWeek, num2, dtfi)); } timeOnly = false; break; case 'e': goto IL_64F; case 'f': goto IL_1E3; case 'g': num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); stringBuilder.Append(dtfi.GetEraName(calendar.GetEra(dateTime))); break; case 'h': { num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); int num3 = dateTime.Hour % 12; if (num3 == 0) { num3 = 12; } DateTimeFormat.FormatDigits(stringBuilder, num3, num2); break; } default: if (c != 'm') { goto IL_64F; } num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); DateTimeFormat.FormatDigits(stringBuilder, dateTime.Minute, num2); break; } } } else if (c <= 't') { if (c != 's') { if (c != 't') { goto IL_64F; } num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); if (num2 == 1) { if (dateTime.Hour < 12) { if (dtfi.AMDesignator.Length >= 1) { stringBuilder.Append(dtfi.AMDesignator[0]); } } else if (dtfi.PMDesignator.Length >= 1) { stringBuilder.Append(dtfi.PMDesignator[0]); } } else { stringBuilder.Append((dateTime.Hour < 12) ? dtfi.AMDesignator : dtfi.PMDesignator); } } else { num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); DateTimeFormat.FormatDigits(stringBuilder, dateTime.Second, num2); } } else if (c != 'y') { if (c != 'z') { goto IL_64F; } num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); DateTimeFormat.FormatCustomizedTimeZone(dateTime, offset, format, num2, timeOnly, stringBuilder); } else { int year = calendar.GetYear(dateTime); num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); if (flag2 && !AppContextSwitches.FormatJapaneseFirstYearAsANumber && year == 1 && ((i + num2 < format.Length && format[i + num2] == "年"[0]) || (i + num2 < format.Length - 1 && format[i + num2] == '\'' && format[i + num2 + 1] == "年"[0]))) { stringBuilder.Append("元"[0]); } else if (dtfi.HasForceTwoDigitYears) { DateTimeFormat.FormatDigits(stringBuilder, year, (num2 <= 2) ? num2 : 2); } else if (calendar.ID == 8) { DateTimeFormat.HebrewFormatDigits(stringBuilder, year); } else if (num2 <= 2) { DateTimeFormat.FormatDigits(stringBuilder, year % 100, num2); } else { string format2 = "D" + num2; stringBuilder.Append(year.ToString(format2, CultureInfo.InvariantCulture)); } timeOnly = false; } IL_65B: i += num2; continue; IL_1E3: num2 = DateTimeFormat.ParseRepeatPattern(format, i, c); if (num2 > 7) { throw new FormatException(Environment.GetResourceString("Format_InvalidString")); } long num4 = dateTime.Ticks % 10000000L; num4 /= (long)Math.Pow(10.0, (double)(7 - num2)); if (c == 'f') { stringBuilder.Append(((int)num4).ToString(DateTimeFormat.fixedNumberFormats[num2 - 1], CultureInfo.InvariantCulture)); goto IL_65B; } int num5 = num2; while (num5 > 0 && num4 % 10L == 0L) { num4 /= 10L; num5--; } if (num5 > 0) { stringBuilder.Append(((int)num4).ToString(DateTimeFormat.fixedNumberFormats[num5 - 1], CultureInfo.InvariantCulture)); goto IL_65B; } if (stringBuilder.Length > 0 && stringBuilder[stringBuilder.Length - 1] == '.') { stringBuilder.Remove(stringBuilder.Length - 1, 1); goto IL_65B; } goto IL_65B; IL_64F: stringBuilder.Append(c); num2 = 1; goto IL_65B; } return(StringBuilderCache.GetStringAndRelease(stringBuilder)); }
private static string FormatCustomized(DateTime dateTime, string format, DateTimeFormatInfo dtfi, TimeSpan offset) { Calendar calendar = dtfi.Calendar; StringBuilder stringBuilder1 = StringBuilderCache.Acquire(16); bool flag = calendar.ID == 8; bool timeOnly = true; int index1 = 0; while (index1 < format.Length) { char patternChar = format[index1]; int num1; if ((uint)patternChar <= 75U) { if ((uint)patternChar <= 47U) { if ((uint)patternChar <= 37U) { if ((int)patternChar != 34) { if ((int)patternChar == 37) { int nextChar = DateTimeFormat.ParseNextChar(format, index1); if (nextChar < 0 || nextChar == 37) { throw new FormatException(Environment.GetResourceString("Format_InvalidString")); } stringBuilder1.Append(DateTimeFormat.FormatCustomized(dateTime, ((char)nextChar).ToString(), dtfi, offset)); num1 = 2; goto label_85; } else { goto label_84; } } } else if ((int)patternChar != 39) { if ((int)patternChar == 47) { stringBuilder1.Append(dtfi.DateSeparator); num1 = 1; goto label_85; } else { goto label_84; } } StringBuilder result = new StringBuilder(); num1 = DateTimeFormat.ParseQuoteString(format, index1, result); stringBuilder1.Append((object)result); goto label_85; } else if ((uint)patternChar <= 70U) { if ((int)patternChar != 58) { if ((int)patternChar != 70) { goto label_84; } } else { stringBuilder1.Append(dtfi.TimeSeparator); num1 = 1; goto label_85; } } else if ((int)patternChar != 72) { if ((int)patternChar == 75) { num1 = 1; DateTimeFormat.FormatCustomizedRoundripTimeZone(dateTime, offset, stringBuilder1); goto label_85; } else { goto label_84; } } else { num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); DateTimeFormat.FormatDigits(stringBuilder1, dateTime.Hour, num1); goto label_85; } } else if ((uint)patternChar <= 109U) { if ((uint)patternChar <= 92U) { if ((int)patternChar != 77) { if ((int)patternChar == 92) { int nextChar = DateTimeFormat.ParseNextChar(format, index1); if (nextChar < 0) { throw new FormatException(Environment.GetResourceString("Format_InvalidString")); } stringBuilder1.Append((char)nextChar); num1 = 2; goto label_85; } else { goto label_84; } } else { num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); int month = calendar.GetMonth(dateTime); if (num1 <= 2) { if (flag) { DateTimeFormat.HebrewFormatDigits(stringBuilder1, month); } else { DateTimeFormat.FormatDigits(stringBuilder1, month, num1); } } else if (flag) { stringBuilder1.Append(DateTimeFormat.FormatHebrewMonthName(dateTime, month, num1, dtfi)); } else if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != DateTimeFormatFlags.None && num1 >= 4) { stringBuilder1.Append(dtfi.internalGetMonthName(month, DateTimeFormat.IsUseGenitiveForm(format, index1, num1, 'd') ? MonthNameStyles.Genitive : MonthNameStyles.Regular, false)); } else { stringBuilder1.Append(DateTimeFormat.FormatMonth(month, num1, dtfi)); } timeOnly = false; goto label_85; } } else { switch (patternChar) { case 'd': num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); if (num1 <= 2) { int dayOfMonth = calendar.GetDayOfMonth(dateTime); if (flag) { DateTimeFormat.HebrewFormatDigits(stringBuilder1, dayOfMonth); } else { DateTimeFormat.FormatDigits(stringBuilder1, dayOfMonth, num1); } } else { int dayOfWeek = (int)calendar.GetDayOfWeek(dateTime); stringBuilder1.Append(DateTimeFormat.FormatDayOfWeek(dayOfWeek, num1, dtfi)); } timeOnly = false; goto label_85; case 'f': break; case 'g': num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); stringBuilder1.Append(dtfi.GetEraName(calendar.GetEra(dateTime))); goto label_85; case 'h': num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); int num2 = dateTime.Hour % 12; if (num2 == 0) { num2 = 12; } DateTimeFormat.FormatDigits(stringBuilder1, num2, num1); goto label_85; case 'm': num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); DateTimeFormat.FormatDigits(stringBuilder1, dateTime.Minute, num1); goto label_85; default: goto label_84; } } } else if ((uint)patternChar <= 116U) { if ((int)patternChar != 115) { if ((int)patternChar == 116) { num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); if (num1 == 1) { if (dateTime.Hour < 12) { if (dtfi.AMDesignator.Length >= 1) { stringBuilder1.Append(dtfi.AMDesignator[0]); goto label_85; } else { goto label_85; } } else if (dtfi.PMDesignator.Length >= 1) { stringBuilder1.Append(dtfi.PMDesignator[0]); goto label_85; } else { goto label_85; } } else { stringBuilder1.Append(dateTime.Hour < 12 ? dtfi.AMDesignator : dtfi.PMDesignator); goto label_85; } } else { goto label_84; } } else { num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); DateTimeFormat.FormatDigits(stringBuilder1, dateTime.Second, num1); goto label_85; } } else if ((int)patternChar != 121) { if ((int)patternChar == 122) { num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); DateTimeFormat.FormatCustomizedTimeZone(dateTime, offset, format, num1, timeOnly, stringBuilder1); goto label_85; } else { goto label_84; } } else { int year = calendar.GetYear(dateTime); num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); if (dtfi.HasForceTwoDigitYears) { DateTimeFormat.FormatDigits(stringBuilder1, year, num1 <= 2 ? num1 : 2); } else if (calendar.ID == 8) { DateTimeFormat.HebrewFormatDigits(stringBuilder1, year); } else if (num1 <= 2) { DateTimeFormat.FormatDigits(stringBuilder1, year % 100, num1); } else { string format1 = "D" + (object)num1; stringBuilder1.Append(year.ToString(format1, (IFormatProvider)CultureInfo.InvariantCulture)); } timeOnly = false; goto label_85; } num1 = DateTimeFormat.ParseRepeatPattern(format, index1, patternChar); if (num1 > 7) { throw new FormatException(Environment.GetResourceString("Format_InvalidString")); } long num3 = dateTime.Ticks % 10000000L / (long)Math.Pow(10.0, (double)(7 - num1)); if ((int)patternChar == 102) { stringBuilder1.Append(((int)num3).ToString(DateTimeFormat.fixedNumberFormats[num1 - 1], (IFormatProvider)CultureInfo.InvariantCulture)); goto label_85; } else { int num4; for (num4 = num1; num4 > 0 && num3 % 10L == 0L; --num4) { num3 /= 10L; } if (num4 > 0) { stringBuilder1.Append(((int)num3).ToString(DateTimeFormat.fixedNumberFormats[num4 - 1], (IFormatProvider)CultureInfo.InvariantCulture)); goto label_85; } else if (stringBuilder1.Length > 0) { StringBuilder stringBuilder2 = stringBuilder1; int index2 = stringBuilder2.Length - 1; if ((int)stringBuilder2[index2] == 46) { StringBuilder stringBuilder3 = stringBuilder1; int startIndex = stringBuilder3.Length - 1; int length = 1; stringBuilder3.Remove(startIndex, length); goto label_85; } else { goto label_85; } } else { goto label_85; } } label_84: stringBuilder1.Append(patternChar); num1 = 1; label_85: index1 += num1; } return(StringBuilderCache.GetStringAndRelease(stringBuilder1)); }