Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
DateTimeFormat.cs
Go to the documentation of this file.
5using System.Text;
6
7namespace System;
8
9internal static class DateTimeFormat
10{
11 internal static char[] allStandardFormats = new char[19]
12 {
13 'd', 'D', 'f', 'F', 'g', 'G', 'm', 'M', 'o', 'O',
14 'r', 'R', 's', 't', 'T', 'u', 'U', 'y', 'Y'
15 };
16
17 internal static readonly DateTimeFormatInfo InvariantFormatInfo = CultureInfo.InvariantCulture.DateTimeFormat;
18
19 internal static readonly string[] InvariantAbbreviatedMonthNames = InvariantFormatInfo.AbbreviatedMonthNames;
20
21 internal static readonly string[] InvariantAbbreviatedDayNames = InvariantFormatInfo.AbbreviatedDayNames;
22
23 internal static string[] fixedNumberFormats = new string[7] { "0", "00", "000", "0000", "00000", "000000", "0000000" };
24
25 internal static void FormatDigits(StringBuilder outputBuffer, int value, int len)
26 {
27 FormatDigits(outputBuffer, value, len, overrideLengthLimit: false);
28 }
29
30 internal unsafe static void FormatDigits(StringBuilder outputBuffer, int value, int len, bool overrideLengthLimit)
31 {
32 if (!overrideLengthLimit && len > 2)
33 {
34 len = 2;
35 }
36 char* ptr = stackalloc char[16];
37 char* ptr2 = ptr + 16;
38 int num = value;
39 do
40 {
41 *(--ptr2) = (char)(num % 10 + 48);
42 num /= 10;
43 }
44 while (num != 0 && ptr2 > ptr);
45 int i;
46 for (i = (int)(ptr + 16 - ptr2); i < len; i++)
47 {
48 if (ptr2 <= ptr)
49 {
50 break;
51 }
52 *(--ptr2) = '0';
53 }
54 outputBuffer.Append(ptr2, i);
55 }
56
57 private static void HebrewFormatDigits(StringBuilder outputBuffer, int digits)
58 {
59 HebrewNumber.Append(outputBuffer, digits);
60 }
61
62 internal static int ParseRepeatPattern(ReadOnlySpan<char> format, int pos, char patternChar)
63 {
64 int length = format.Length;
65 int i;
66 for (i = pos + 1; i < length && format[i] == patternChar; i++)
67 {
68 }
69 return i - pos;
70 }
71
72 private static string FormatDayOfWeek(int dayOfWeek, int repeat, DateTimeFormatInfo dtfi)
73 {
74 if (repeat == 3)
75 {
76 return dtfi.GetAbbreviatedDayName((DayOfWeek)dayOfWeek);
77 }
78 return dtfi.GetDayName((DayOfWeek)dayOfWeek);
79 }
80
81 private static string FormatMonth(int month, int repeatCount, DateTimeFormatInfo dtfi)
82 {
83 if (repeatCount == 3)
84 {
85 return dtfi.GetAbbreviatedMonthName(month);
86 }
87 return dtfi.GetMonthName(month);
88 }
89
90 private static string FormatHebrewMonthName(DateTime time, int month, int repeatCount, DateTimeFormatInfo dtfi)
91 {
92 if (dtfi.Calendar.IsLeapYear(dtfi.Calendar.GetYear(time)))
93 {
94 return dtfi.InternalGetMonthName(month, MonthNameStyles.LeapYear, repeatCount == 3);
95 }
96 if (month >= 7)
97 {
98 month++;
99 }
100 if (repeatCount == 3)
101 {
102 return dtfi.GetAbbreviatedMonthName(month);
103 }
104 return dtfi.GetMonthName(month);
105 }
106
107 internal static int ParseQuoteString(ReadOnlySpan<char> format, int pos, StringBuilder result)
108 {
109 int length = format.Length;
110 int num = pos;
111 char c = format[pos++];
112 bool flag = false;
113 while (pos < length)
114 {
115 char c2 = format[pos++];
116 if (c2 == c)
117 {
118 flag = true;
119 break;
120 }
121 if (c2 == '\\')
122 {
123 if (pos >= length)
124 {
126 }
127 result.Append(format[pos++]);
128 }
129 else
130 {
131 result.Append(c2);
132 }
133 }
134 if (!flag)
135 {
137 }
138 return pos - num;
139 }
140
141 internal static int ParseNextChar(ReadOnlySpan<char> format, int pos)
142 {
143 if (pos >= format.Length - 1)
144 {
145 return -1;
146 }
147 return format[pos + 1];
148 }
149
151 {
152 int num = 0;
153 int num2 = index - 1;
154 while (num2 >= 0 && format[num2] != patternToMatch)
155 {
156 num2--;
157 }
158 if (num2 >= 0)
159 {
160 while (--num2 >= 0 && format[num2] == patternToMatch)
161 {
162 num++;
163 }
164 if (num <= 1)
165 {
166 return true;
167 }
168 }
169 for (num2 = index + tokenLen; num2 < format.Length && format[num2] != patternToMatch; num2++)
170 {
171 }
172 if (num2 < format.Length)
173 {
174 num = 0;
175 while (++num2 < format.Length && format[num2] == patternToMatch)
176 {
177 num++;
178 }
179 if (num <= 1)
180 {
181 return true;
182 }
183 }
184 return false;
185 }
186
188 {
189 Calendar calendar = dtfi.Calendar;
190 bool flag = false;
191 if (result == null)
192 {
193 flag = true;
194 result = StringBuilderCache.Acquire();
195 }
196 bool flag2 = calendar.ID == CalendarId.HEBREW;
197 bool flag3 = calendar.ID == CalendarId.JAPAN;
198 bool timeOnly = true;
199 int num;
200 for (int i = 0; i < format.Length; i += num)
201 {
202 char c = format[i];
203 switch (c)
204 {
205 case 'g':
206 num = ParseRepeatPattern(format, i, c);
207 result.Append(dtfi.GetEraName(calendar.GetEra(dateTime)));
208 break;
209 case 'h':
210 {
211 num = ParseRepeatPattern(format, i, c);
212 int num3 = dateTime.Hour % 12;
213 if (num3 == 0)
214 {
215 num3 = 12;
216 }
217 FormatDigits(result, num3, num);
218 break;
219 }
220 case 'H':
221 num = ParseRepeatPattern(format, i, c);
222 FormatDigits(result, dateTime.Hour, num);
223 break;
224 case 'm':
225 num = ParseRepeatPattern(format, i, c);
226 FormatDigits(result, dateTime.Minute, num);
227 break;
228 case 's':
229 num = ParseRepeatPattern(format, i, c);
230 FormatDigits(result, dateTime.Second, num);
231 break;
232 case 'F':
233 case 'f':
234 num = ParseRepeatPattern(format, i, c);
235 if (num <= 7)
236 {
237 long num4 = dateTime.Ticks % 10000000;
238 num4 /= (long)Math.Pow(10.0, 7 - num);
239 if (c == 'f')
240 {
241 result.AppendSpanFormattable((int)num4, fixedNumberFormats[num - 1], CultureInfo.InvariantCulture);
242 break;
243 }
244 int num5 = num;
245 while (num5 > 0 && num4 % 10 == 0L)
246 {
247 num4 /= 10;
248 num5--;
249 }
250 if (num5 > 0)
251 {
252 result.AppendSpanFormattable((int)num4, fixedNumberFormats[num5 - 1], CultureInfo.InvariantCulture);
253 }
254 else if (result.Length > 0 && result[result.Length - 1] == '.')
255 {
256 result.Remove(result.Length - 1, 1);
257 }
258 break;
259 }
260 if (flag)
261 {
263 }
265 case 't':
266 num = ParseRepeatPattern(format, i, c);
267 if (num == 1)
268 {
269 if (dateTime.Hour < 12)
270 {
271 if (dtfi.AMDesignator.Length >= 1)
272 {
273 result.Append(dtfi.AMDesignator[0]);
274 }
275 }
276 else if (dtfi.PMDesignator.Length >= 1)
277 {
278 result.Append(dtfi.PMDesignator[0]);
279 }
280 }
281 else
282 {
283 result.Append((dateTime.Hour < 12) ? dtfi.AMDesignator : dtfi.PMDesignator);
284 }
285 break;
286 case 'd':
287 num = ParseRepeatPattern(format, i, c);
288 if (num <= 2)
289 {
290 int dayOfMonth = calendar.GetDayOfMonth(dateTime);
291 if (flag2)
292 {
294 }
295 else
296 {
297 FormatDigits(result, dayOfMonth, num);
298 }
299 }
300 else
301 {
302 int dayOfWeek = (int)calendar.GetDayOfWeek(dateTime);
303 result.Append(FormatDayOfWeek(dayOfWeek, num, dtfi));
304 }
305 timeOnly = false;
306 break;
307 case 'M':
308 {
309 num = ParseRepeatPattern(format, i, c);
310 int month = calendar.GetMonth(dateTime);
311 if (num <= 2)
312 {
313 if (flag2)
314 {
315 HebrewFormatDigits(result, month);
316 }
317 else
318 {
319 FormatDigits(result, month, num);
320 }
321 }
322 else if (flag2)
323 {
324 result.Append(FormatHebrewMonthName(dateTime, month, num, dtfi));
325 }
326 else if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0)
327 {
328 result.Append(dtfi.InternalGetMonthName(month, IsUseGenitiveForm(format, i, num, 'd') ? MonthNameStyles.Genitive : MonthNameStyles.Regular, num == 3));
329 }
330 else
331 {
332 result.Append(FormatMonth(month, num, dtfi));
333 }
334 timeOnly = false;
335 break;
336 }
337 case 'y':
338 {
339 int year = calendar.GetYear(dateTime);
340 num = ParseRepeatPattern(format, i, c);
341 if (flag3 && !LocalAppContextSwitches.FormatJapaneseFirstYearAsANumber && year == 1 && ((i + num < format.Length && format[i + num] == '年') || (i + num < format.Length - 1 && format[i + num] == '\'' && format[i + num + 1] == '年')))
342 {
343 result.Append("元"[0]);
344 }
345 else if (dtfi.HasForceTwoDigitYears)
346 {
347 FormatDigits(result, year, (num <= 2) ? num : 2);
348 }
349 else if (calendar.ID == CalendarId.HEBREW)
350 {
351 HebrewFormatDigits(result, year);
352 }
353 else if (num <= 2)
354 {
355 FormatDigits(result, year % 100, num);
356 }
357 else if (num <= 16)
358 {
359 FormatDigits(result, year, num, overrideLengthLimit: true);
360 }
361 else
362 {
363 result.Append(year.ToString("D" + num.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture));
364 }
365 timeOnly = false;
366 break;
367 }
368 case 'z':
369 num = ParseRepeatPattern(format, i, c);
371 break;
372 case 'K':
373 num = 1;
375 break;
376 case ':':
377 result.Append(dtfi.TimeSeparator);
378 num = 1;
379 break;
380 case '/':
381 result.Append(dtfi.DateSeparator);
382 num = 1;
383 break;
384 case '"':
385 case '\'':
386 num = ParseQuoteString(format, i, result);
387 break;
388 case '%':
389 {
390 int num2 = ParseNextChar(format, i);
391 if (num2 >= 0 && num2 != 37)
392 {
393 char reference = (char)num2;
395 num = 2;
396 break;
397 }
398 if (flag)
399 {
401 }
403 }
404 case '\\':
405 {
406 int num2 = ParseNextChar(format, i);
407 if (num2 >= 0)
408 {
409 result.Append((char)num2);
410 num = 2;
411 break;
412 }
413 if (flag)
414 {
416 }
418 }
419 default:
420 result.Append(c);
421 num = 1;
422 break;
423 }
424 }
425 return result;
426 }
427
429 {
430 if (offset.Ticks == long.MinValue)
431 {
432 offset = ((timeOnly && dateTime.Ticks < 864000000000L) ? TimeZoneInfo.GetLocalUtcOffset(DateTime.Now, TimeZoneInfoOptions.NoThrowOnInvalidTime) : ((dateTime.Kind != DateTimeKind.Utc) ? TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime) : default(TimeSpan)));
433 }
434 if (offset.Ticks >= 0)
435 {
436 result.Append('+');
437 }
438 else
439 {
440 result.Append('-');
441 offset = offset.Negate();
442 }
445 if (tokenLen <= 1)
446 {
447 stringBuilder = result;
452 handler.AppendFormatted(offset.Hours, "0");
453 stringBuilder2.Append(provider, ref handler);
454 return;
455 }
456 stringBuilder = result;
461 handler2.AppendFormatted(offset.Hours, "00");
463 if (tokenLen >= 3)
464 {
465 stringBuilder = result;
470 handler3.AppendLiteral(":");
471 handler3.AppendFormatted(offset.Minutes, "00");
473 }
474 }
475
477 {
478 if (offset.Ticks == long.MinValue)
479 {
480 switch (dateTime.Kind)
481 {
482 case DateTimeKind.Local:
483 break;
484 case DateTimeKind.Utc:
485 result.Append('Z');
486 return;
487 default:
488 return;
489 }
491 }
492 if (offset.Ticks >= 0)
493 {
494 result.Append('+');
495 }
496 else
497 {
498 result.Append('-');
499 offset = offset.Negate();
500 }
501 Append2DigitNumber(result, offset.Hours);
502 result.Append(':');
503 Append2DigitNumber(result, offset.Minutes);
504 }
505
506 private static void Append2DigitNumber(StringBuilder result, int val)
507 {
508 result.Append((char)(48 + val / 10));
509 result.Append((char)(48 + val % 10));
510 }
511
513 {
514 switch (format[0])
515 {
516 case 'd':
517 return dtfi.ShortDatePattern;
518 case 'D':
519 return dtfi.LongDatePattern;
520 case 'f':
521 return dtfi.LongDatePattern + " " + dtfi.ShortTimePattern;
522 case 'F':
523 return dtfi.FullDateTimePattern;
524 case 'g':
525 return dtfi.GeneralShortTimePattern;
526 case 'G':
527 return dtfi.GeneralLongTimePattern;
528 case 'M':
529 case 'm':
530 return dtfi.MonthDayPattern;
531 case 'O':
532 case 'o':
533 return "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK";
534 case 'R':
535 case 'r':
536 return dtfi.RFC1123Pattern;
537 case 's':
538 return dtfi.SortableDateTimePattern;
539 case 't':
540 return dtfi.ShortTimePattern;
541 case 'T':
542 return dtfi.LongTimePattern;
543 case 'u':
544 return dtfi.UniversalSortableDateTimePattern;
545 case 'U':
546 return dtfi.FullDateTimePattern;
547 case 'Y':
548 case 'y':
549 return dtfi.YearMonthPattern;
550 default:
552 }
553 }
554
556 {
557 switch (format[0])
558 {
559 case 'O':
560 case 'o':
562 break;
563 case 'R':
564 case 'r':
565 case 'u':
566 if (offset.Ticks != long.MinValue)
567 {
568 dateTime -= offset;
569 }
571 break;
572 case 's':
574 break;
575 case 'U':
576 if (offset.Ticks != long.MinValue)
577 {
579 }
580 dtfi = (DateTimeFormatInfo)dtfi.Clone();
581 if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
582 {
583 dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
584 }
585 dateTime = dateTime.ToUniversalTime();
586 break;
587 }
588 return GetRealFormat(format, dtfi);
589 }
590
591 internal static string Format(DateTime dateTime, string format, IFormatProvider provider)
592 {
593 return Format(dateTime, format, provider, new TimeSpan(long.MinValue));
594 }
595
597 {
598 if (format != null && format.Length == 1)
599 {
600 switch (format[0])
601 {
602 case 'O':
603 case 'o':
604 {
607 return destination.Slice(0, charsWritten2).ToString();
608 }
609 case 'R':
610 case 'r':
611 {
612 string text = string.FastAllocateString(29);
613 TryFormatR(dateTime, offset, new Span<char>(ref text.GetRawStringData(), text.Length), out var _);
614 return text;
615 }
616 }
617 }
618 DateTimeFormatInfo instance = DateTimeFormatInfo.GetInstance(provider);
620 }
621
626
628 {
629 if (format.Length == 1)
630 {
631 switch (format[0])
632 {
633 case 'O':
634 case 'o':
636 case 'R':
637 case 'r':
639 }
640 }
641 DateTimeFormatInfo instance = DateTimeFormatInfo.GetInstance(provider);
643 bool flag = stringBuilder.Length <= destination.Length;
644 if (flag)
645 {
648 }
649 else
650 {
651 charsWritten = 0;
652 }
654 return flag;
655 }
656
658 {
659 if (format.Length == 0)
660 {
661 bool flag = false;
662 if (dateTime.Ticks < 864000000000L)
663 {
664 switch (dtfi.Calendar.ID)
665 {
666 case CalendarId.JAPAN:
667 case CalendarId.TAIWAN:
668 case CalendarId.HIJRI:
669 case CalendarId.HEBREW:
670 case CalendarId.JULIAN:
671 case CalendarId.PERSIAN:
672 case CalendarId.UMALQURA:
673 flag = true;
675 break;
676 }
677 }
678 format = ((offset.Ticks != long.MinValue) ? ((ReadOnlySpan<char>)(flag ? "yyyy'-'MM'-'ddTHH':'mm':'ss zzz" : dtfi.DateTimeOffsetPattern)) : ((ReadOnlySpan<char>)(flag ? "s" : "G")));
679 }
680 if (format.Length == 1)
681 {
683 }
684 return FormatCustomized(dateTime, format, dtfi, offset, null);
685 }
686
688 {
689 int i = 0;
690 while (i < format.Length)
691 {
692 switch (format[i])
693 {
694 case '\\':
695 if (i == format.Length - 1)
696 {
697 if (throwOnError)
698 {
700 }
701 return false;
702 }
703 i += 2;
704 break;
705 case '"':
706 case '\'':
707 {
708 char c;
709 for (c = format[i++]; i < format.Length && format[i] != c; i++)
710 {
711 }
712 if (i >= format.Length)
713 {
714 if (throwOnError)
715 {
717 }
718 return false;
719 }
720 i++;
721 break;
722 }
723 case ':':
724 case 'F':
725 case 'H':
726 case 'K':
727 case 'f':
728 case 'h':
729 case 'm':
730 case 's':
731 case 't':
732 case 'z':
733 if (throwOnError)
734 {
736 }
737 return false;
738 default:
739 i++;
740 break;
741 }
742 }
743 return true;
744 }
745
747 {
748 int length = format.Length;
749 int i = 0;
750 while (i < length)
751 {
752 switch (format[i])
753 {
754 case '\\':
755 if (i == length - 1)
756 {
757 if (throwOnError)
758 {
760 }
761 return false;
762 }
763 i += 2;
764 break;
765 case '"':
766 case '\'':
767 {
768 char c;
769 for (c = format[i++]; i < length && format[i] != c; i++)
770 {
771 }
772 if (i >= length)
773 {
774 if (throwOnError)
775 {
777 }
778 return false;
779 }
780 i++;
781 break;
782 }
783 case '/':
784 case 'M':
785 case 'd':
786 case 'k':
787 case 'y':
788 case 'z':
789 if (throwOnError)
790 {
792 }
793 return false;
794 default:
795 i++;
796 break;
797 }
798 }
799 return true;
800 }
801
802 internal static bool TryFormatTimeOnlyO(int hour, int minute, int second, long fraction, Span<char> destination)
803 {
804 if (destination.Length < 16)
805 {
806 return false;
807 }
808 WriteTwoDecimalDigits((uint)hour, destination, 0);
809 destination[2] = ':';
810 WriteTwoDecimalDigits((uint)minute, destination, 3);
811 destination[5] = ':';
812 WriteTwoDecimalDigits((uint)second, destination, 6);
813 destination[8] = '.';
814 WriteDigits((uint)fraction, destination.Slice(9, 7));
815 return true;
816 }
817
818 internal static bool TryFormatTimeOnlyR(int hour, int minute, int second, Span<char> destination)
819 {
820 if (destination.Length < 8)
821 {
822 return false;
823 }
824 WriteTwoDecimalDigits((uint)hour, destination, 0);
825 destination[2] = ':';
826 WriteTwoDecimalDigits((uint)minute, destination, 3);
827 destination[5] = ':';
828 WriteTwoDecimalDigits((uint)second, destination, 6);
829 return true;
830 }
831
832 internal static bool TryFormatDateOnlyO(int year, int month, int day, Span<char> destination)
833 {
834 if (destination.Length < 10)
835 {
836 return false;
837 }
839 destination[4] = '-';
840 WriteTwoDecimalDigits((uint)month, destination, 5);
841 destination[7] = '-';
842 WriteTwoDecimalDigits((uint)day, destination, 8);
843 return true;
844 }
845
846 internal static bool TryFormatDateOnlyR(DayOfWeek dayOfWeek, int year, int month, int day, Span<char> destination)
847 {
848 if (destination.Length < 16)
849 {
850 return false;
851 }
852 string text = InvariantAbbreviatedDayNames[(int)dayOfWeek];
853 string text2 = InvariantAbbreviatedMonthNames[month - 1];
854 destination[0] = text[0];
855 destination[1] = text[1];
856 destination[2] = text[2];
857 destination[3] = ',';
858 destination[4] = ' ';
859 WriteTwoDecimalDigits((uint)day, destination, 5);
860 destination[7] = ' ';
861 destination[8] = text2[0];
862 destination[9] = text2[1];
863 destination[10] = text2[2];
864 destination[11] = ' ';
866 return true;
867 }
868
870 {
871 int num = 27;
873 if (offset.Ticks == long.MinValue)
874 {
875 dateTimeKind = dateTime.Kind;
876 switch (dateTimeKind)
877 {
878 case DateTimeKind.Local:
879 offset = TimeZoneInfo.Local.GetUtcOffset(dateTime);
880 num += 6;
881 break;
882 case DateTimeKind.Utc:
883 num++;
884 break;
885 }
886 }
887 else
888 {
889 num += 6;
890 }
891 if (destination.Length < num)
892 {
893 charsWritten = 0;
894 return false;
895 }
896 charsWritten = num;
897 _ = ref destination[26];
898 dateTime.GetDate(out var year, out var month, out var day);
899 dateTime.GetTimePrecise(out var hour, out var minute, out var second, out var tick);
901 destination[4] = '-';
902 WriteTwoDecimalDigits((uint)month, destination, 5);
903 destination[7] = '-';
904 WriteTwoDecimalDigits((uint)day, destination, 8);
905 destination[10] = 'T';
906 WriteTwoDecimalDigits((uint)hour, destination, 11);
907 destination[13] = ':';
908 WriteTwoDecimalDigits((uint)minute, destination, 14);
909 destination[16] = ':';
910 WriteTwoDecimalDigits((uint)second, destination, 17);
911 destination[19] = '.';
912 WriteDigits((uint)tick, destination.Slice(20, 7));
913 switch (dateTimeKind)
914 {
915 case DateTimeKind.Local:
916 {
917 int num2 = (int)(offset.Ticks / 600000000);
918 char c;
919 if (num2 < 0)
920 {
921 c = '-';
922 num2 = -num2;
923 }
924 else
925 {
926 c = '+';
927 }
928 int result;
929 int value = Math.DivRem(num2, 60, out result);
930 WriteTwoDecimalDigits((uint)result, destination, 31);
931 destination[30] = ':';
933 destination[27] = c;
934 break;
935 }
936 case DateTimeKind.Utc:
937 destination[27] = 'Z';
938 break;
939 }
940 return true;
941 }
942
944 {
945 if (destination.Length <= 28)
946 {
947 charsWritten = 0;
948 return false;
949 }
950 if (offset.Ticks != long.MinValue)
951 {
952 dateTime -= offset;
953 }
954 dateTime.GetDate(out var year, out var month, out var day);
955 dateTime.GetTime(out var hour, out var minute, out var second);
956 string text = InvariantAbbreviatedDayNames[(int)dateTime.DayOfWeek];
957 string text2 = InvariantAbbreviatedMonthNames[month - 1];
958 destination[0] = text[0];
959 destination[1] = text[1];
960 destination[2] = text[2];
961 destination[3] = ',';
962 destination[4] = ' ';
963 WriteTwoDecimalDigits((uint)day, destination, 5);
964 destination[7] = ' ';
965 destination[8] = text2[0];
966 destination[9] = text2[1];
967 destination[10] = text2[2];
968 destination[11] = ' ';
970 destination[16] = ' ';
971 WriteTwoDecimalDigits((uint)hour, destination, 17);
972 destination[19] = ':';
973 WriteTwoDecimalDigits((uint)minute, destination, 20);
974 destination[22] = ':';
975 WriteTwoDecimalDigits((uint)second, destination, 23);
976 destination[25] = ' ';
977 destination[26] = 'G';
978 destination[27] = 'M';
979 destination[28] = 'T';
980 charsWritten = 29;
981 return true;
982 }
983
984 [MethodImpl(MethodImplOptions.AggressiveInlining)]
986 {
987 uint num = 48 + value;
988 value /= 10;
989 destination[offset + 1] = (char)(num - value * 10);
990 destination[offset] = (char)(48 + value);
991 }
992
993 [MethodImpl(MethodImplOptions.AggressiveInlining)]
994 private static void WriteFourDecimalDigits(uint value, Span<char> buffer, int startingIndex = 0)
995 {
996 uint num = 48 + value;
997 value /= 10;
998 buffer[startingIndex + 3] = (char)(num - value * 10);
999 num = 48 + value;
1000 value /= 10;
1001 buffer[startingIndex + 2] = (char)(num - value * 10);
1002 num = 48 + value;
1003 value /= 10;
1004 buffer[startingIndex + 1] = (char)(num - value * 10);
1005 buffer[startingIndex] = (char)(48 + value);
1006 }
1007
1008 [MethodImpl(MethodImplOptions.AggressiveInlining)]
1009 private static void WriteDigits(ulong value, Span<char> buffer)
1010 {
1011 for (int num = buffer.Length - 1; num >= 1; num--)
1012 {
1013 ulong num2 = 48 + value;
1014 value /= 10;
1015 buffer[num] = (char)(num2 - value * 10);
1016 }
1017 buffer[0] = (char)(48 + value);
1018 }
1019
1021 {
1022 string[] array;
1023 switch (format)
1024 {
1025 case 'D':
1026 case 'F':
1027 case 'G':
1028 case 'M':
1029 case 'T':
1030 case 'Y':
1031 case 'd':
1032 case 'f':
1033 case 'g':
1034 case 'm':
1035 case 't':
1036 case 'y':
1037 {
1038 string[] allDateTimePatterns = dtfi.GetAllDateTimePatterns(format);
1039 array = new string[allDateTimePatterns.Length];
1040 for (int j = 0; j < allDateTimePatterns.Length; j++)
1041 {
1043 }
1044 break;
1045 }
1046 case 'U':
1047 {
1048 DateTime dateTime2 = dateTime.ToUniversalTime();
1049 string[] allDateTimePatterns = dtfi.GetAllDateTimePatterns(format);
1050 array = new string[allDateTimePatterns.Length];
1051 for (int i = 0; i < allDateTimePatterns.Length; i++)
1052 {
1054 }
1055 break;
1056 }
1057 case 'O':
1058 case 'R':
1059 case 'o':
1060 case 'r':
1061 case 's':
1062 case 'u':
1063 array = new string[1] { Format(dateTime, char.ToString(format), dtfi) };
1064 break;
1065 default:
1067 }
1068 return array;
1069 }
1070
1072 {
1073 List<string> list = new List<string>(132);
1074 for (int i = 0; i < allStandardFormats.Length; i++)
1075 {
1077 for (int j = 0; j < allDateTimes.Length; j++)
1078 {
1079 list.Add(allDateTimes[j]);
1080 }
1081 }
1082 return list.ToArray();
1083 }
1084}
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
static int ParseNextChar(ReadOnlySpan< char > format, int pos)
static string[] GetAllDateTimes(DateTime dateTime, char format, DateTimeFormatInfo dtfi)
static readonly string[] InvariantAbbreviatedDayNames
static bool IsValidCustomTimeFormat(ReadOnlySpan< char > format, bool throwOnError)
static string FormatMonth(int month, int repeatCount, DateTimeFormatInfo dtfi)
static string Format(DateTime dateTime, string format, IFormatProvider provider, TimeSpan offset)
static string FormatHebrewMonthName(DateTime time, int month, int repeatCount, DateTimeFormatInfo dtfi)
static bool IsUseGenitiveForm(ReadOnlySpan< char > format, int index, int tokenLen, char patternToMatch)
static bool TryFormatDateOnlyO(int year, int month, int day, Span< char > destination)
static bool TryFormatR(DateTime dateTime, TimeSpan offset, Span< char > destination, out int charsWritten)
static StringBuilder FormatCustomized(DateTime dateTime, ReadOnlySpan< char > format, DateTimeFormatInfo dtfi, TimeSpan offset, StringBuilder result)
static StringBuilder FormatStringBuilder(DateTime dateTime, ReadOnlySpan< char > format, DateTimeFormatInfo dtfi, TimeSpan offset)
static bool TryFormat(DateTime dateTime, Span< char > destination, out int charsWritten, ReadOnlySpan< char > format, IFormatProvider provider)
static readonly DateTimeFormatInfo InvariantFormatInfo
static int ParseRepeatPattern(ReadOnlySpan< char > format, int pos, char patternChar)
static string FormatDayOfWeek(int dayOfWeek, int repeat, DateTimeFormatInfo dtfi)
static string Format(DateTime dateTime, string format, IFormatProvider provider)
static unsafe void FormatDigits(StringBuilder outputBuffer, int value, int len, bool overrideLengthLimit)
static bool TryFormatO(DateTime dateTime, TimeSpan offset, Span< char > destination, out int charsWritten)
static void FormatCustomizedTimeZone(DateTime dateTime, TimeSpan offset, int tokenLen, bool timeOnly, StringBuilder result)
static char[] allStandardFormats
static string[] GetAllDateTimes(DateTime dateTime, DateTimeFormatInfo dtfi)
static void WriteTwoDecimalDigits(uint value, Span< char > destination, int offset)
static int ParseQuoteString(ReadOnlySpan< char > format, int pos, StringBuilder result)
static bool TryFormatTimeOnlyR(int hour, int minute, int second, Span< char > destination)
static void FormatDigits(StringBuilder outputBuffer, int value, int len)
static void WriteDigits(ulong value, Span< char > buffer)
static bool TryFormatTimeOnlyO(int hour, int minute, int second, long fraction, Span< char > destination)
static bool IsValidCustomDateFormat(ReadOnlySpan< char > format, bool throwOnError)
static bool TryFormat(DateTime dateTime, Span< char > destination, out int charsWritten, ReadOnlySpan< char > format, IFormatProvider provider, TimeSpan offset)
static string[] fixedNumberFormats
static bool TryFormatDateOnlyR(DayOfWeek dayOfWeek, int year, int month, int day, Span< char > destination)
static void HebrewFormatDigits(StringBuilder outputBuffer, int digits)
static readonly string[] InvariantAbbreviatedMonthNames
static void WriteFourDecimalDigits(uint value, Span< char > buffer, int startingIndex=0)
static string ExpandPredefinedFormat(ReadOnlySpan< char > format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, TimeSpan offset)
static string GetRealFormat(ReadOnlySpan< char > format, DateTimeFormatInfo dtfi)
static void FormatCustomizedRoundripTimeZone(DateTime dateTime, TimeSpan offset, StringBuilder result)
static void Append2DigitNumber(StringBuilder result, int val)
DayOfWeek GetDayOfWeek(DateTime time)
int GetYear(DateTime time)
int GetDayOfMonth(DateTime time)
virtual CalendarId ID
Definition Calendar.cs:19
int GetMonth(DateTime time)
int GetEra(DateTime time)
static CultureInfo InvariantCulture
static void Append(StringBuilder outputBuffer, int Number)
static double Pow(double x, double y)
static int DivRem(int a, int b, out int result)
Definition Math.cs:329
static string Format_BadQuote
Definition SR.cs:1338
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Format_InvalidString
Definition SR.cs:1354
Definition SR.cs:7
static string GetStringAndRelease(StringBuilder sb)
static void Release(StringBuilder sb)
static StringBuilder Acquire(int capacity=16)
StringBuilder Remove(int startIndex, int length)
StringBuilder Append(char value, int repeatCount)
static TimeZoneInfo Local
static TimeSpan GetLocalUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
DayOfWeek
Definition DayOfWeek.cs:4
static DateTime Now
Definition DateTime.cs:103