Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DateTimeParse.cs
Go to the documentation of this file.
3using System.Text;
4
5namespace System;
6
7internal static class DateTimeParse
8{
9 internal delegate bool MatchNumberDelegate(ref __DTString str, int digitLen, out int result);
10
11 internal enum DTT
12 {
13 End,
14 NumEnd,
15 NumAmpm,
27 YearEnd,
29 Era,
31 Unk,
33 Max
34 }
35
36 internal enum TM
37 {
38 NotSet = -1,
39 AM,
40 PM
41 }
42
43 internal enum DS
44 {
45 BEGIN,
46 N,
47 NN,
48 D_Nd,
49 D_NN,
50 D_NNd,
51 D_M,
52 D_MN,
53 D_NM,
54 D_MNd,
55 D_NDS,
56 D_Y,
57 D_YN,
58 D_YNd,
59 D_YM,
60 D_YMd,
61 D_S,
62 T_S,
63 T_Nt,
64 T_NNt,
65 ERROR,
66 DX_NN,
67 DX_NNN,
68 DX_MN,
69 DX_NM,
70 DX_MNN,
71 DX_DS,
72 DX_DSN,
73 DX_NDS,
74 DX_NNDS,
75 DX_YNN,
76 DX_YMN,
77 DX_YN,
78 DX_YM,
79 TX_N,
80 TX_NN,
81 TX_NNN,
82 TX_TS,
83 DX_NNY
84 }
85
87
88 private static readonly DS[][] s_dateParsingStates = new DS[20][]
89 {
90 new DS[18]
91 {
92 DS.BEGIN,
93 DS.ERROR,
94 DS.TX_N,
95 DS.N,
96 DS.D_Nd,
97 DS.T_Nt,
98 DS.ERROR,
99 DS.D_M,
100 DS.D_M,
101 DS.D_S,
102 DS.T_S,
103 DS.BEGIN,
104 DS.D_Y,
105 DS.D_Y,
106 DS.ERROR,
107 DS.BEGIN,
108 DS.BEGIN,
109 DS.ERROR
110 },
111 new DS[18]
112 {
113 DS.ERROR,
114 DS.DX_NN,
115 DS.ERROR,
116 DS.NN,
117 DS.D_NNd,
118 DS.ERROR,
119 DS.DX_NM,
120 DS.D_NM,
121 DS.D_MNd,
122 DS.D_NDS,
123 DS.ERROR,
124 DS.N,
125 DS.D_YN,
126 DS.D_YNd,
127 DS.DX_YN,
128 DS.N,
129 DS.N,
130 DS.ERROR
131 },
132 new DS[18]
133 {
134 DS.DX_NN,
135 DS.DX_NNN,
136 DS.TX_N,
137 DS.DX_NNN,
138 DS.ERROR,
139 DS.T_Nt,
140 DS.DX_MNN,
141 DS.DX_MNN,
142 DS.ERROR,
143 DS.ERROR,
144 DS.T_S,
145 DS.NN,
146 DS.DX_NNY,
147 DS.ERROR,
148 DS.DX_NNY,
149 DS.NN,
150 DS.NN,
151 DS.ERROR
152 },
153 new DS[18]
154 {
155 DS.ERROR,
156 DS.DX_NN,
157 DS.ERROR,
158 DS.D_NN,
159 DS.D_NNd,
160 DS.ERROR,
161 DS.DX_NM,
162 DS.D_MN,
163 DS.D_MNd,
164 DS.ERROR,
165 DS.ERROR,
166 DS.D_Nd,
167 DS.D_YN,
168 DS.D_YNd,
169 DS.DX_YN,
170 DS.ERROR,
171 DS.D_Nd,
172 DS.ERROR
173 },
174 new DS[18]
175 {
176 DS.DX_NN,
177 DS.DX_NNN,
178 DS.TX_N,
179 DS.DX_NNN,
180 DS.ERROR,
181 DS.T_Nt,
182 DS.DX_MNN,
183 DS.DX_MNN,
184 DS.ERROR,
185 DS.DX_DS,
186 DS.T_S,
187 DS.D_NN,
188 DS.DX_NNY,
189 DS.ERROR,
190 DS.DX_NNY,
191 DS.ERROR,
192 DS.D_NN,
193 DS.ERROR
194 },
195 new DS[18]
196 {
197 DS.ERROR,
198 DS.DX_NNN,
199 DS.DX_NNN,
200 DS.DX_NNN,
201 DS.ERROR,
202 DS.ERROR,
203 DS.DX_MNN,
204 DS.DX_MNN,
205 DS.ERROR,
206 DS.DX_DS,
207 DS.ERROR,
208 DS.D_NNd,
209 DS.DX_NNY,
210 DS.ERROR,
211 DS.DX_NNY,
212 DS.ERROR,
213 DS.D_NNd,
214 DS.ERROR
215 },
216 new DS[18]
217 {
218 DS.ERROR,
219 DS.DX_MN,
220 DS.ERROR,
221 DS.D_MN,
222 DS.D_MNd,
223 DS.ERROR,
224 DS.ERROR,
225 DS.ERROR,
226 DS.ERROR,
227 DS.ERROR,
228 DS.ERROR,
229 DS.D_M,
230 DS.D_YM,
231 DS.D_YMd,
232 DS.DX_YM,
233 DS.ERROR,
234 DS.D_M,
235 DS.ERROR
236 },
237 new DS[18]
238 {
239 DS.DX_MN,
240 DS.DX_MNN,
241 DS.DX_MNN,
242 DS.DX_MNN,
243 DS.ERROR,
244 DS.T_Nt,
245 DS.ERROR,
246 DS.ERROR,
247 DS.ERROR,
248 DS.DX_DS,
249 DS.T_S,
250 DS.D_MN,
251 DS.DX_YMN,
252 DS.ERROR,
253 DS.DX_YMN,
254 DS.ERROR,
255 DS.D_MN,
256 DS.ERROR
257 },
258 new DS[18]
259 {
260 DS.DX_NM,
261 DS.DX_MNN,
262 DS.DX_MNN,
263 DS.DX_MNN,
264 DS.ERROR,
265 DS.T_Nt,
266 DS.ERROR,
267 DS.ERROR,
268 DS.ERROR,
269 DS.DX_DS,
270 DS.T_S,
271 DS.D_NM,
272 DS.DX_YMN,
273 DS.ERROR,
274 DS.DX_YMN,
275 DS.ERROR,
276 DS.D_NM,
277 DS.ERROR
278 },
279 new DS[18]
280 {
281 DS.ERROR,
282 DS.DX_MNN,
283 DS.ERROR,
284 DS.DX_MNN,
285 DS.ERROR,
286 DS.ERROR,
287 DS.ERROR,
288 DS.ERROR,
289 DS.ERROR,
290 DS.ERROR,
291 DS.ERROR,
292 DS.D_MNd,
293 DS.DX_YMN,
294 DS.ERROR,
295 DS.DX_YMN,
296 DS.ERROR,
297 DS.D_MNd,
298 DS.ERROR
299 },
300 new DS[18]
301 {
302 DS.DX_NDS,
303 DS.DX_NNDS,
304 DS.DX_NNDS,
305 DS.DX_NNDS,
306 DS.ERROR,
307 DS.T_Nt,
308 DS.ERROR,
309 DS.ERROR,
310 DS.ERROR,
311 DS.D_NDS,
312 DS.T_S,
313 DS.D_NDS,
314 DS.ERROR,
315 DS.ERROR,
316 DS.ERROR,
317 DS.ERROR,
318 DS.D_NDS,
319 DS.ERROR
320 },
321 new DS[18]
322 {
323 DS.ERROR,
324 DS.DX_YN,
325 DS.ERROR,
326 DS.D_YN,
327 DS.D_YNd,
328 DS.ERROR,
329 DS.DX_YM,
330 DS.D_YM,
331 DS.D_YMd,
332 DS.D_YM,
333 DS.ERROR,
334 DS.D_Y,
335 DS.ERROR,
336 DS.ERROR,
337 DS.ERROR,
338 DS.ERROR,
339 DS.D_Y,
340 DS.ERROR
341 },
342 new DS[18]
343 {
344 DS.DX_YN,
345 DS.DX_YNN,
346 DS.DX_YNN,
347 DS.DX_YNN,
348 DS.ERROR,
349 DS.ERROR,
350 DS.DX_YMN,
351 DS.DX_YMN,
352 DS.ERROR,
353 DS.ERROR,
354 DS.ERROR,
355 DS.D_YN,
356 DS.ERROR,
357 DS.ERROR,
358 DS.ERROR,
359 DS.ERROR,
360 DS.D_YN,
361 DS.ERROR
362 },
363 new DS[18]
364 {
365 DS.ERROR,
366 DS.DX_YNN,
367 DS.DX_YNN,
368 DS.DX_YNN,
369 DS.ERROR,
370 DS.ERROR,
371 DS.DX_YMN,
372 DS.DX_YMN,
373 DS.ERROR,
374 DS.ERROR,
375 DS.ERROR,
376 DS.D_YN,
377 DS.ERROR,
378 DS.ERROR,
379 DS.ERROR,
380 DS.ERROR,
381 DS.D_YN,
382 DS.ERROR
383 },
384 new DS[18]
385 {
386 DS.DX_YM,
387 DS.DX_YMN,
388 DS.DX_YMN,
389 DS.DX_YMN,
390 DS.ERROR,
391 DS.ERROR,
392 DS.ERROR,
393 DS.ERROR,
394 DS.ERROR,
395 DS.ERROR,
396 DS.ERROR,
397 DS.D_YM,
398 DS.ERROR,
399 DS.ERROR,
400 DS.ERROR,
401 DS.ERROR,
402 DS.D_YM,
403 DS.ERROR
404 },
405 new DS[18]
406 {
407 DS.ERROR,
408 DS.DX_YMN,
409 DS.DX_YMN,
410 DS.DX_YMN,
411 DS.ERROR,
412 DS.ERROR,
413 DS.ERROR,
414 DS.ERROR,
415 DS.ERROR,
416 DS.ERROR,
417 DS.ERROR,
418 DS.D_YM,
419 DS.ERROR,
420 DS.ERROR,
421 DS.ERROR,
422 DS.ERROR,
423 DS.D_YM,
424 DS.ERROR
425 },
426 new DS[18]
427 {
428 DS.DX_DS,
429 DS.DX_DSN,
430 DS.TX_N,
431 DS.T_Nt,
432 DS.ERROR,
433 DS.T_Nt,
434 DS.ERROR,
435 DS.ERROR,
436 DS.ERROR,
437 DS.D_S,
438 DS.T_S,
439 DS.D_S,
440 DS.ERROR,
441 DS.ERROR,
442 DS.ERROR,
443 DS.ERROR,
444 DS.D_S,
445 DS.ERROR
446 },
447 new DS[18]
448 {
449 DS.TX_TS,
450 DS.TX_TS,
451 DS.TX_TS,
452 DS.T_Nt,
453 DS.D_Nd,
454 DS.ERROR,
455 DS.ERROR,
456 DS.ERROR,
457 DS.ERROR,
458 DS.D_S,
459 DS.T_S,
460 DS.T_S,
461 DS.ERROR,
462 DS.ERROR,
463 DS.ERROR,
464 DS.T_S,
465 DS.T_S,
466 DS.ERROR
467 },
468 new DS[18]
469 {
470 DS.ERROR,
471 DS.TX_NN,
472 DS.TX_NN,
473 DS.TX_NN,
474 DS.ERROR,
475 DS.T_NNt,
476 DS.DX_NM,
477 DS.D_NM,
478 DS.ERROR,
479 DS.ERROR,
480 DS.T_S,
481 DS.ERROR,
482 DS.ERROR,
483 DS.ERROR,
484 DS.ERROR,
485 DS.T_Nt,
486 DS.T_Nt,
487 DS.TX_NN
488 },
489 new DS[18]
490 {
491 DS.ERROR,
492 DS.TX_NNN,
493 DS.TX_NNN,
494 DS.TX_NNN,
495 DS.ERROR,
496 DS.ERROR,
497 DS.ERROR,
498 DS.ERROR,
499 DS.ERROR,
500 DS.ERROR,
501 DS.T_S,
502 DS.T_NNt,
503 DS.ERROR,
504 DS.ERROR,
505 DS.ERROR,
506 DS.T_NNt,
507 DS.T_NNt,
508 DS.TX_NNN
509 }
510 };
511
513 {
514 DateTimeResult result = default(DateTimeResult);
515 result.Init(s);
516 if (TryParseExact(s, format, dtfi, style, ref result))
517 {
518 return result.parsedDate;
519 }
520 throw GetDateTimeParseException(ref result);
521 }
522
524 {
525 DateTimeResult result = default(DateTimeResult);
526 result.Init(s);
527 result.flags |= ParseFlags.CaptureOffset;
528 if (TryParseExact(s, format, dtfi, style, ref result))
529 {
530 offset = result.timeZoneOffset;
531 return result.parsedDate;
532 }
533 throw GetDateTimeParseException(ref result);
534 }
535
537 {
538 DateTimeResult result2 = default(DateTimeResult);
539 result2.Init(s);
540 if (TryParseExact(s, format, dtfi, style, ref result2))
541 {
542 result = result2.parsedDate;
543 return true;
544 }
545 result = DateTime.MinValue;
546 return false;
547 }
548
550 {
551 DateTimeResult result2 = default(DateTimeResult);
552 result2.Init(s);
553 result2.flags |= ParseFlags.CaptureOffset;
554 if (TryParseExact(s, format, dtfi, style, ref result2))
555 {
556 result = result2.parsedDate;
557 offset = result2.timeZoneOffset;
558 return true;
559 }
560 result = DateTime.MinValue;
562 return false;
563 }
564
566 {
567 if (s.Length == 0)
568 {
569 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDateTime");
570 return false;
571 }
572 if (format.Length == 0)
573 {
574 result.SetBadFormatSpecifierFailure();
575 return false;
576 }
577 return DoStrictParse(s, format, style, dtfi, ref result);
578 }
579
581 {
582 DateTimeResult result = default(DateTimeResult);
583 result.Init(s);
584 if (TryParseExactMultiple(s, formats, dtfi, style, ref result))
585 {
586 return result.parsedDate;
587 }
588 throw GetDateTimeParseException(ref result);
589 }
590
592 {
593 DateTimeResult result = default(DateTimeResult);
594 result.Init(s);
595 result.flags |= ParseFlags.CaptureOffset;
596 if (TryParseExactMultiple(s, formats, dtfi, style, ref result))
597 {
598 offset = result.timeZoneOffset;
599 return result.parsedDate;
600 }
601 throw GetDateTimeParseException(ref result);
602 }
603
604 internal static bool TryParseExactMultiple(ReadOnlySpan<char> s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result, out TimeSpan offset)
605 {
606 DateTimeResult result2 = default(DateTimeResult);
607 result2.Init(s);
608 result2.flags |= ParseFlags.CaptureOffset;
609 if (TryParseExactMultiple(s, formats, dtfi, style, ref result2))
610 {
611 result = result2.parsedDate;
612 offset = result2.timeZoneOffset;
613 return true;
614 }
615 result = DateTime.MinValue;
617 return false;
618 }
619
620 internal static bool TryParseExactMultiple(ReadOnlySpan<char> s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result)
621 {
622 DateTimeResult result2 = default(DateTimeResult);
623 result2.Init(s);
624 if (TryParseExactMultiple(s, formats, dtfi, style, ref result2))
625 {
626 result = result2.parsedDate;
627 return true;
628 }
629 result = DateTime.MinValue;
630 return false;
631 }
632
634 {
635 if (formats == null)
636 {
637 result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "formats");
638 return false;
639 }
640 if (s.Length == 0)
641 {
642 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDateTime");
643 return false;
644 }
645 if (formats.Length == 0)
646 {
647 result.SetFailure(ParseFailureKind.Format, "Format_NoFormatSpecifier");
648 return false;
649 }
650 foreach (string text in formats)
651 {
652 if (string.IsNullOrEmpty(text))
653 {
654 result.SetBadFormatSpecifierFailure();
655 return false;
656 }
657 DateTimeResult result2 = default(DateTimeResult);
658 result2.Init(s);
659 result2.flags = result.flags;
660 if (TryParseExact(s, text, dtfi, style, ref result2))
661 {
662 result.parsedDate = result2.parsedDate;
663 result.timeZoneOffset = result2.timeZoneOffset;
664 return true;
665 }
666 }
667 result.SetBadDateTimeFailure();
668 return false;
669 }
670
671 private static bool MatchWord(ref __DTString str, string target)
672 {
673 if (target.Length > str.Value.Length - str.Index)
674 {
675 return false;
676 }
677 if (str.CompareInfo.Compare(str.Value.Slice(str.Index, target.Length), target, CompareOptions.IgnoreCase) != 0)
678 {
679 return false;
680 }
681 int num = str.Index + target.Length;
682 if (num < str.Value.Length)
683 {
684 char c = str.Value[num];
685 if (char.IsLetter(c))
686 {
687 return false;
688 }
689 }
690 str.Index = num;
691 if (str.Index < str.Length)
692 {
693 str.m_current = str.Value[str.Index];
694 }
695 return true;
696 }
697
698 private static bool GetTimeZoneName(ref __DTString str)
699 {
700 if (MatchWord(ref str, "GMT"))
701 {
702 return true;
703 }
704 if (MatchWord(ref str, "Z"))
705 {
706 return true;
707 }
708 return false;
709 }
710
711 internal static bool IsDigit(char ch)
712 {
713 return (uint)(ch - 48) <= 9u;
714 }
715
716 private static bool ParseFraction(ref __DTString str, out double result)
717 {
718 result = 0.0;
719 double num = 0.1;
720 int num2 = 0;
721 char current;
722 while (str.GetNext() && IsDigit(current = str.m_current))
723 {
724 result += (double)(current - 48) * num;
725 num *= 0.1;
726 num2++;
727 }
728 return num2 > 0;
729 }
730
731 private static bool ParseTimeZone(ref __DTString str, ref TimeSpan result)
732 {
733 int num = 0;
734 DTSubString subString = str.GetSubString();
735 if (subString.length != 1)
736 {
737 return false;
738 }
739 char c = subString[0];
740 if (c != '+' && c != '-')
741 {
742 return false;
743 }
744 str.ConsumeSubString(subString);
745 subString = str.GetSubString();
746 if (subString.type != DTSubStringType.Number)
747 {
748 return false;
749 }
750 int value = subString.value;
751 int hours;
752 switch (subString.length)
753 {
754 case 1:
755 case 2:
756 hours = value;
757 str.ConsumeSubString(subString);
758 subString = str.GetSubString();
759 if (subString.length == 1 && subString[0] == ':')
760 {
761 str.ConsumeSubString(subString);
762 subString = str.GetSubString();
763 if (subString.type != DTSubStringType.Number || subString.length < 1 || subString.length > 2)
764 {
765 return false;
766 }
767 num = subString.value;
768 str.ConsumeSubString(subString);
769 }
770 break;
771 case 3:
772 case 4:
773 hours = value / 100;
774 num = value % 100;
775 str.ConsumeSubString(subString);
776 break;
777 default:
778 return false;
779 }
780 if (num < 0 || num >= 60)
781 {
782 return false;
783 }
784 result = new TimeSpan(hours, num, 0);
785 if (c == '-')
786 {
787 result = result.Negate();
788 }
789 return true;
790 }
791
792 private static bool HandleTimeZone(ref __DTString str, ref DateTimeResult result)
793 {
794 if (str.Index < str.Length - 1)
795 {
796 char c = str.Value[str.Index];
797 int num = 0;
798 while (char.IsWhiteSpace(c) && str.Index + num < str.Length - 1)
799 {
800 num++;
801 c = str.Value[str.Index + num];
802 }
803 if (c == '+' || c == '-')
804 {
805 str.Index += num;
806 if ((result.flags & ParseFlags.TimeZoneUsed) != 0)
807 {
808 result.SetBadDateTimeFailure();
809 return false;
810 }
811 result.flags |= ParseFlags.TimeZoneUsed;
812 if (!ParseTimeZone(ref str, ref result.timeZoneOffset))
813 {
814 result.SetBadDateTimeFailure();
815 return false;
816 }
817 }
818 }
819 return true;
820 }
821
822 private static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref DateTimeRawInfo raw, ref DateTimeResult result, ref DateTimeFormatInfo dtfi, DateTimeStyles styles)
823 {
824 dtok.dtt = DTT.Unk;
825 str.GetRegularToken(out var tokenType, out var tokenValue, dtfi);
826 int indexBeforeSeparator;
827 char charBeforeSeparator;
828 switch (tokenType)
829 {
830 case TokenType.NumberToken:
831 case TokenType.YearNumberToken:
832 {
833 if (raw.numCount == 3 || tokenValue == -1)
834 {
835 result.SetBadDateTimeFailure();
836 return false;
837 }
838 if (dps == DS.T_NNt && str.Index < str.Length - 1)
839 {
840 char c = str.Value[str.Index];
841 if (c == '.')
842 {
843 ParseFraction(ref str, out raw.fraction);
844 }
845 }
846 if ((dps == DS.T_NNt || dps == DS.T_Nt) && str.Index < str.Length - 1 && !HandleTimeZone(ref str, ref result))
847 {
848 return false;
849 }
850 dtok.num = tokenValue;
851 TokenType separatorToken;
852 if (tokenType == TokenType.YearNumberToken)
853 {
854 if (raw.year == -1)
855 {
856 raw.year = tokenValue;
857 switch (separatorToken = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator))
858 {
859 case TokenType.SEP_End:
860 dtok.dtt = DTT.YearEnd;
861 break;
862 case TokenType.SEP_Am:
863 case TokenType.SEP_Pm:
864 if (raw.timeMark == TM.NotSet)
865 {
866 raw.timeMark = ((separatorToken != TokenType.SEP_Am) ? TM.PM : TM.AM);
867 dtok.dtt = DTT.YearSpace;
868 }
869 else
870 {
871 result.SetBadDateTimeFailure();
872 }
873 break;
874 case TokenType.SEP_Space:
875 dtok.dtt = DTT.YearSpace;
876 break;
877 case TokenType.SEP_Date:
878 dtok.dtt = DTT.YearDateSep;
879 break;
880 case TokenType.SEP_Time:
881 if (!raw.hasSameDateAndTimeSeparators)
882 {
883 result.SetBadDateTimeFailure();
884 return false;
885 }
886 dtok.dtt = DTT.YearDateSep;
887 break;
888 case TokenType.SEP_DateOrOffset:
889 if (s_dateParsingStates[(int)dps][13] == DS.ERROR && s_dateParsingStates[(int)dps][12] > DS.ERROR)
890 {
891 str.Index = indexBeforeSeparator;
892 str.m_current = charBeforeSeparator;
893 dtok.dtt = DTT.YearSpace;
894 }
895 else
896 {
897 dtok.dtt = DTT.YearDateSep;
898 }
899 break;
900 case TokenType.SEP_YearSuff:
901 case TokenType.SEP_MonthSuff:
902 case TokenType.SEP_DaySuff:
903 dtok.dtt = DTT.NumDatesuff;
904 dtok.suffix = separatorToken;
905 break;
906 case TokenType.SEP_HourSuff:
907 case TokenType.SEP_MinuteSuff:
908 case TokenType.SEP_SecondSuff:
909 dtok.dtt = DTT.NumTimesuff;
910 dtok.suffix = separatorToken;
911 break;
912 default:
913 result.SetBadDateTimeFailure();
914 return false;
915 }
916 return true;
917 }
918 result.SetBadDateTimeFailure();
919 return false;
920 }
921 switch (separatorToken = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator))
922 {
923 case TokenType.SEP_End:
924 dtok.dtt = DTT.NumEnd;
925 raw.AddNumber(dtok.num);
926 break;
927 case TokenType.SEP_Am:
928 case TokenType.SEP_Pm:
929 if (raw.timeMark == TM.NotSet)
930 {
931 raw.timeMark = ((separatorToken != TokenType.SEP_Am) ? TM.PM : TM.AM);
932 dtok.dtt = DTT.NumAmpm;
933 if (dps == DS.D_NN && !ProcessTerminalState(DS.DX_NN, ref result, ref styles, ref raw, dtfi))
934 {
935 return false;
936 }
937 raw.AddNumber(dtok.num);
938 if ((dps == DS.T_NNt || dps == DS.T_Nt) && !HandleTimeZone(ref str, ref result))
939 {
940 return false;
941 }
942 }
943 else
944 {
945 result.SetBadDateTimeFailure();
946 }
947 break;
948 case TokenType.SEP_Space:
949 dtok.dtt = DTT.NumSpace;
950 raw.AddNumber(dtok.num);
951 break;
952 case TokenType.SEP_Date:
953 dtok.dtt = DTT.NumDatesep;
954 raw.AddNumber(dtok.num);
955 break;
956 case TokenType.SEP_DateOrOffset:
957 if (s_dateParsingStates[(int)dps][4] == DS.ERROR && s_dateParsingStates[(int)dps][3] > DS.ERROR)
958 {
959 str.Index = indexBeforeSeparator;
960 str.m_current = charBeforeSeparator;
961 dtok.dtt = DTT.NumSpace;
962 }
963 else
964 {
965 dtok.dtt = DTT.NumDatesep;
966 }
967 raw.AddNumber(dtok.num);
968 break;
969 case TokenType.SEP_Time:
970 if (raw.hasSameDateAndTimeSeparators && (dps == DS.D_Y || dps == DS.D_YN || dps == DS.D_YNd || dps == DS.D_YM || dps == DS.D_YMd))
971 {
972 dtok.dtt = DTT.NumDatesep;
973 raw.AddNumber(dtok.num);
974 }
975 else
976 {
977 dtok.dtt = DTT.NumTimesep;
978 raw.AddNumber(dtok.num);
979 }
980 break;
981 case TokenType.SEP_YearSuff:
982 try
983 {
984 dtok.num = dtfi.Calendar.ToFourDigitYear(tokenValue);
985 }
987 {
988 result.SetBadDateTimeFailure();
989 return false;
990 }
991 dtok.dtt = DTT.NumDatesuff;
992 dtok.suffix = separatorToken;
993 break;
994 case TokenType.SEP_MonthSuff:
995 case TokenType.SEP_DaySuff:
996 dtok.dtt = DTT.NumDatesuff;
997 dtok.suffix = separatorToken;
998 break;
999 case TokenType.SEP_HourSuff:
1000 case TokenType.SEP_MinuteSuff:
1001 case TokenType.SEP_SecondSuff:
1002 dtok.dtt = DTT.NumTimesuff;
1003 dtok.suffix = separatorToken;
1004 break;
1005 case TokenType.SEP_LocalTimeMark:
1006 dtok.dtt = DTT.NumLocalTimeMark;
1007 raw.AddNumber(dtok.num);
1008 break;
1009 default:
1010 result.SetBadDateTimeFailure();
1011 return false;
1012 }
1013 break;
1014 }
1015 case TokenType.HebrewNumber:
1016 {
1017 TokenType separatorToken;
1018 if (tokenValue >= 100)
1019 {
1020 if (raw.year == -1)
1021 {
1022 raw.year = tokenValue;
1023 TokenType tokenType2 = (separatorToken = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator));
1024 if (tokenType2 != TokenType.SEP_End)
1025 {
1026 if (tokenType2 != TokenType.SEP_Space)
1027 {
1028 if (tokenType2 != TokenType.SEP_DateOrOffset || s_dateParsingStates[(int)dps][12] <= DS.ERROR)
1029 {
1030 result.SetBadDateTimeFailure();
1031 return false;
1032 }
1033 str.Index = indexBeforeSeparator;
1034 str.m_current = charBeforeSeparator;
1035 dtok.dtt = DTT.YearSpace;
1036 }
1037 else
1038 {
1039 dtok.dtt = DTT.YearSpace;
1040 }
1041 }
1042 else
1043 {
1044 dtok.dtt = DTT.YearEnd;
1045 }
1046 break;
1047 }
1048 result.SetBadDateTimeFailure();
1049 return false;
1050 }
1051 dtok.num = tokenValue;
1052 raw.AddNumber(dtok.num);
1053 switch (separatorToken = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator))
1054 {
1055 case TokenType.SEP_End:
1056 dtok.dtt = DTT.NumEnd;
1057 break;
1058 case TokenType.SEP_Space:
1059 case TokenType.SEP_Date:
1060 dtok.dtt = DTT.NumDatesep;
1061 break;
1062 case TokenType.SEP_DateOrOffset:
1063 if (s_dateParsingStates[(int)dps][4] == DS.ERROR && s_dateParsingStates[(int)dps][3] > DS.ERROR)
1064 {
1065 str.Index = indexBeforeSeparator;
1066 str.m_current = charBeforeSeparator;
1067 dtok.dtt = DTT.NumSpace;
1068 }
1069 else
1070 {
1071 dtok.dtt = DTT.NumDatesep;
1072 }
1073 break;
1074 default:
1075 result.SetBadDateTimeFailure();
1076 return false;
1077 }
1078 break;
1079 }
1080 case TokenType.DayOfWeekToken:
1081 if (raw.dayOfWeek == -1)
1082 {
1083 raw.dayOfWeek = tokenValue;
1084 dtok.dtt = DTT.DayOfWeek;
1085 break;
1086 }
1087 result.SetBadDateTimeFailure();
1088 return false;
1089 case TokenType.MonthToken:
1090 if (raw.month == -1)
1091 {
1092 TokenType separatorToken;
1093 switch (separatorToken = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator))
1094 {
1095 case TokenType.SEP_End:
1096 dtok.dtt = DTT.MonthEnd;
1097 break;
1098 case TokenType.SEP_Space:
1099 dtok.dtt = DTT.MonthSpace;
1100 break;
1101 case TokenType.SEP_Date:
1102 dtok.dtt = DTT.MonthDatesep;
1103 break;
1104 case TokenType.SEP_Time:
1105 if (!raw.hasSameDateAndTimeSeparators)
1106 {
1107 result.SetBadDateTimeFailure();
1108 return false;
1109 }
1110 dtok.dtt = DTT.MonthDatesep;
1111 break;
1112 case TokenType.SEP_DateOrOffset:
1113 if (s_dateParsingStates[(int)dps][8] == DS.ERROR && s_dateParsingStates[(int)dps][7] > DS.ERROR)
1114 {
1115 str.Index = indexBeforeSeparator;
1116 str.m_current = charBeforeSeparator;
1117 dtok.dtt = DTT.MonthSpace;
1118 }
1119 else
1120 {
1121 dtok.dtt = DTT.MonthDatesep;
1122 }
1123 break;
1124 default:
1125 result.SetBadDateTimeFailure();
1126 return false;
1127 }
1128 raw.month = tokenValue;
1129 break;
1130 }
1131 result.SetBadDateTimeFailure();
1132 return false;
1133 case TokenType.EraToken:
1134 if (result.era != -1)
1135 {
1136 result.era = tokenValue;
1137 dtok.dtt = DTT.Era;
1138 break;
1139 }
1140 result.SetBadDateTimeFailure();
1141 return false;
1142 case TokenType.JapaneseEraToken:
1144 {
1145 return false;
1146 }
1147 result.calendar = JapaneseCalendar.GetDefaultInstance();
1148 dtfi = DateTimeFormatInfo.GetJapaneseCalendarDTFI();
1149 if (result.era != -1)
1150 {
1151 result.era = tokenValue;
1152 dtok.dtt = DTT.Era;
1153 break;
1154 }
1155 result.SetBadDateTimeFailure();
1156 return false;
1157 case TokenType.TEraToken:
1159 {
1160 return false;
1161 }
1162 result.calendar = TaiwanCalendar.GetDefaultInstance();
1163 dtfi = DateTimeFormatInfo.GetTaiwanCalendarDTFI();
1164 if (result.era != -1)
1165 {
1166 result.era = tokenValue;
1167 dtok.dtt = DTT.Era;
1168 break;
1169 }
1170 result.SetBadDateTimeFailure();
1171 return false;
1172 case TokenType.TimeZoneToken:
1173 if ((result.flags & ParseFlags.TimeZoneUsed) != 0)
1174 {
1175 result.SetBadDateTimeFailure();
1176 return false;
1177 }
1178 dtok.dtt = DTT.TimeZone;
1179 result.flags |= ParseFlags.TimeZoneUsed;
1180 result.timeZoneOffset = new TimeSpan(0L);
1181 result.flags |= ParseFlags.TimeZoneUtc;
1182 break;
1183 case TokenType.EndOfString:
1184 dtok.dtt = DTT.End;
1185 break;
1186 case TokenType.Am:
1187 case TokenType.Pm:
1188 if (raw.timeMark == TM.NotSet)
1189 {
1190 raw.timeMark = (TM)tokenValue;
1191 break;
1192 }
1193 result.SetBadDateTimeFailure();
1194 return false;
1195 case TokenType.UnknownToken:
1196 if (char.IsLetter(str.m_current))
1197 {
1198 result.SetFailure(ParseFailureKind.FormatWithOriginalDateTimeAndParameter, "Format_UnknownDateTimeWord", str.Index);
1199 return false;
1200 }
1201 if ((str.m_current == '-' || str.m_current == '+') && (result.flags & ParseFlags.TimeZoneUsed) == 0)
1202 {
1203 int index = str.Index;
1204 if (ParseTimeZone(ref str, ref result.timeZoneOffset))
1205 {
1206 result.flags |= ParseFlags.TimeZoneUsed;
1207 return true;
1208 }
1209 str.Index = index;
1210 }
1211 if (VerifyValidPunctuation(ref str))
1212 {
1213 return true;
1214 }
1215 result.SetBadDateTimeFailure();
1216 return false;
1217 }
1218 return true;
1219 }
1220
1221 private static bool VerifyValidPunctuation(ref __DTString str)
1222 {
1223 switch (str.Value[str.Index])
1224 {
1225 case '#':
1226 {
1227 bool flag = false;
1228 bool flag2 = false;
1229 for (int j = 0; j < str.Length; j++)
1230 {
1231 char c = str.Value[j];
1232 switch (c)
1233 {
1234 case '#':
1235 if (flag)
1236 {
1237 if (flag2)
1238 {
1239 return false;
1240 }
1241 flag2 = true;
1242 }
1243 else
1244 {
1245 flag = true;
1246 }
1247 break;
1248 case '\0':
1249 if (!flag2)
1250 {
1251 return false;
1252 }
1253 break;
1254 default:
1255 if (!char.IsWhiteSpace(c) && (!flag || flag2))
1256 {
1257 return false;
1258 }
1259 break;
1260 }
1261 }
1262 if (!flag2)
1263 {
1264 return false;
1265 }
1266 str.GetNext();
1267 return true;
1268 }
1269 case '\0':
1270 {
1271 for (int i = str.Index; i < str.Length; i++)
1272 {
1273 if (str.Value[i] != 0)
1274 {
1275 return false;
1276 }
1277 }
1278 str.Index = str.Length;
1279 return true;
1280 }
1281 default:
1282 return false;
1283 }
1284 }
1285
1286 private static bool GetYearMonthDayOrder(string datePattern, out int order)
1287 {
1288 int num = -1;
1289 int num2 = -1;
1290 int num3 = -1;
1291 int num4 = 0;
1292 bool flag = false;
1293 for (int i = 0; i < datePattern.Length && num4 < 3; i++)
1294 {
1295 char c = datePattern[i];
1296 switch (c)
1297 {
1298 case '%':
1299 case '\\':
1300 i++;
1301 continue;
1302 case '"':
1303 case '\'':
1304 flag = !flag;
1305 break;
1306 }
1307 if (flag)
1308 {
1309 continue;
1310 }
1311 switch (c)
1312 {
1313 case 'y':
1314 num = num4++;
1315 for (; i + 1 < datePattern.Length && datePattern[i + 1] == 'y'; i++)
1316 {
1317 }
1318 break;
1319 case 'M':
1320 num2 = num4++;
1321 for (; i + 1 < datePattern.Length && datePattern[i + 1] == 'M'; i++)
1322 {
1323 }
1324 break;
1325 case 'd':
1326 {
1327 int num5 = 1;
1328 for (; i + 1 < datePattern.Length && datePattern[i + 1] == 'd'; i++)
1329 {
1330 num5++;
1331 }
1332 if (num5 <= 2)
1333 {
1334 num3 = num4++;
1335 }
1336 break;
1337 }
1338 }
1339 }
1340 if (num == 0 && num2 == 1 && num3 == 2)
1341 {
1342 order = 0;
1343 return true;
1344 }
1345 if (num2 == 0 && num3 == 1 && num == 2)
1346 {
1347 order = 1;
1348 return true;
1349 }
1350 if (num3 == 0 && num2 == 1 && num == 2)
1351 {
1352 order = 2;
1353 return true;
1354 }
1355 if (num == 0 && num3 == 1 && num2 == 2)
1356 {
1357 order = 3;
1358 return true;
1359 }
1360 order = -1;
1361 return false;
1362 }
1363
1364 private static bool GetYearMonthOrder(string pattern, out int order)
1365 {
1366 int num = -1;
1367 int num2 = -1;
1368 int num3 = 0;
1369 bool flag = false;
1370 for (int i = 0; i < pattern.Length && num3 < 2; i++)
1371 {
1372 char c = pattern[i];
1373 switch (c)
1374 {
1375 case '%':
1376 case '\\':
1377 i++;
1378 continue;
1379 case '"':
1380 case '\'':
1381 flag = !flag;
1382 break;
1383 }
1384 if (flag)
1385 {
1386 continue;
1387 }
1388 switch (c)
1389 {
1390 case 'y':
1391 num = num3++;
1392 for (; i + 1 < pattern.Length && pattern[i + 1] == 'y'; i++)
1393 {
1394 }
1395 break;
1396 case 'M':
1397 num2 = num3++;
1398 for (; i + 1 < pattern.Length && pattern[i + 1] == 'M'; i++)
1399 {
1400 }
1401 break;
1402 }
1403 }
1404 if (num == 0 && num2 == 1)
1405 {
1406 order = 4;
1407 return true;
1408 }
1409 if (num2 == 0 && num == 1)
1410 {
1411 order = 5;
1412 return true;
1413 }
1414 order = -1;
1415 return false;
1416 }
1417
1418 private static bool GetMonthDayOrder(string pattern, out int order)
1419 {
1420 int num = -1;
1421 int num2 = -1;
1422 int num3 = 0;
1423 bool flag = false;
1424 for (int i = 0; i < pattern.Length && num3 < 2; i++)
1425 {
1426 char c = pattern[i];
1427 switch (c)
1428 {
1429 case '%':
1430 case '\\':
1431 i++;
1432 continue;
1433 case '"':
1434 case '\'':
1435 flag = !flag;
1436 break;
1437 }
1438 if (flag)
1439 {
1440 continue;
1441 }
1442 switch (c)
1443 {
1444 case 'd':
1445 {
1446 int num4 = 1;
1447 for (; i + 1 < pattern.Length && pattern[i + 1] == 'd'; i++)
1448 {
1449 num4++;
1450 }
1451 if (num4 <= 2)
1452 {
1453 num2 = num3++;
1454 }
1455 break;
1456 }
1457 case 'M':
1458 num = num3++;
1459 for (; i + 1 < pattern.Length && pattern[i + 1] == 'M'; i++)
1460 {
1461 }
1462 break;
1463 }
1464 }
1465 if (num == 0 && num2 == 1)
1466 {
1467 order = 6;
1468 return true;
1469 }
1470 if (num2 == 0 && num == 1)
1471 {
1472 order = 7;
1473 return true;
1474 }
1475 order = -1;
1476 return false;
1477 }
1478
1479 private static bool TryAdjustYear(ref DateTimeResult result, int year, out int adjustedYear)
1480 {
1481 if (year < 100)
1482 {
1483 try
1484 {
1485 year = result.calendar.ToFourDigitYear(year);
1486 }
1488 {
1489 adjustedYear = -1;
1490 return false;
1491 }
1492 }
1493 adjustedYear = year;
1494 return true;
1495 }
1496
1497 private static bool SetDateYMD(ref DateTimeResult result, int year, int month, int day)
1498 {
1499 if (result.calendar.IsValidDay(year, month, day, result.era))
1500 {
1501 result.SetDate(year, month, day);
1502 return true;
1503 }
1504 return false;
1505 }
1506
1507 private static bool SetDateMDY(ref DateTimeResult result, int month, int day, int year)
1508 {
1509 return SetDateYMD(ref result, year, month, day);
1510 }
1511
1512 private static bool SetDateDMY(ref DateTimeResult result, int day, int month, int year)
1513 {
1514 return SetDateYMD(ref result, year, month, day);
1515 }
1516
1517 private static bool SetDateYDM(ref DateTimeResult result, int year, int day, int month)
1518 {
1519 return SetDateYMD(ref result, year, month, day);
1520 }
1521
1522 private static void GetDefaultYear(ref DateTimeResult result, ref DateTimeStyles styles)
1523 {
1524 result.Year = result.calendar.GetYear(GetDateTimeNow(ref result, ref styles));
1525 result.flags |= ParseFlags.YearDefault;
1526 }
1527
1528 private static bool GetDayOfNN(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
1529 {
1530 if ((result.flags & ParseFlags.HaveDate) != 0)
1531 {
1532 result.SetBadDateTimeFailure();
1533 return false;
1534 }
1535 int number = raw.GetNumber(0);
1536 int number2 = raw.GetNumber(1);
1537 GetDefaultYear(ref result, ref styles);
1538 if (!GetMonthDayOrder(dtfi.MonthDayPattern, out var order))
1539 {
1540 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.MonthDayPattern);
1541 return false;
1542 }
1543 if (order == 6)
1544 {
1545 if (SetDateYMD(ref result, result.Year, number, number2))
1546 {
1547 result.flags |= ParseFlags.HaveDate;
1548 return true;
1549 }
1550 }
1551 else if (SetDateYMD(ref result, result.Year, number2, number))
1552 {
1553 result.flags |= ParseFlags.HaveDate;
1554 return true;
1555 }
1556 result.SetBadDateTimeFailure();
1557 return false;
1558 }
1559
1560 private static bool GetDayOfNNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
1561 {
1562 if ((result.flags & ParseFlags.HaveDate) != 0)
1563 {
1564 result.SetBadDateTimeFailure();
1565 return false;
1566 }
1567 int number = raw.GetNumber(0);
1568 int number2 = raw.GetNumber(1);
1569 int number3 = raw.GetNumber(2);
1570 if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, out var order))
1571 {
1572 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
1573 return false;
1574 }
1575 int adjustedYear;
1576 switch (order)
1577 {
1578 case 0:
1579 if (TryAdjustYear(ref result, number, out adjustedYear) && SetDateYMD(ref result, adjustedYear, number2, number3))
1580 {
1581 result.flags |= ParseFlags.HaveDate;
1582 return true;
1583 }
1584 break;
1585 case 1:
1586 if (TryAdjustYear(ref result, number3, out adjustedYear) && SetDateMDY(ref result, number, number2, adjustedYear))
1587 {
1588 result.flags |= ParseFlags.HaveDate;
1589 return true;
1590 }
1591 break;
1592 case 2:
1593 if (TryAdjustYear(ref result, number3, out adjustedYear) && SetDateDMY(ref result, number, number2, adjustedYear))
1594 {
1595 result.flags |= ParseFlags.HaveDate;
1596 return true;
1597 }
1598 break;
1599 case 3:
1600 if (TryAdjustYear(ref result, number, out adjustedYear) && SetDateYDM(ref result, adjustedYear, number2, number3))
1601 {
1602 result.flags |= ParseFlags.HaveDate;
1603 return true;
1604 }
1605 break;
1606 }
1607 result.SetBadDateTimeFailure();
1608 return false;
1609 }
1610
1611 private static bool GetDayOfMN(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
1612 {
1613 if ((result.flags & ParseFlags.HaveDate) != 0)
1614 {
1615 result.SetBadDateTimeFailure();
1616 return false;
1617 }
1618 if (!GetMonthDayOrder(dtfi.MonthDayPattern, out var order))
1619 {
1620 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.MonthDayPattern);
1621 return false;
1622 }
1623 if (order == 7)
1624 {
1625 if (!GetYearMonthOrder(dtfi.YearMonthPattern, out var order2))
1626 {
1627 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.YearMonthPattern);
1628 return false;
1629 }
1630 if (order2 == 5)
1631 {
1632 if (!TryAdjustYear(ref result, raw.GetNumber(0), out var adjustedYear) || !SetDateYMD(ref result, adjustedYear, raw.month, 1))
1633 {
1634 result.SetBadDateTimeFailure();
1635 return false;
1636 }
1637 return true;
1638 }
1639 }
1640 GetDefaultYear(ref result, ref styles);
1641 if (!SetDateYMD(ref result, result.Year, raw.month, raw.GetNumber(0)))
1642 {
1643 result.SetBadDateTimeFailure();
1644 return false;
1645 }
1646 return true;
1647 }
1648
1649 private static bool GetHebrewDayOfNM(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
1650 {
1651 if (!GetMonthDayOrder(dtfi.MonthDayPattern, out var order))
1652 {
1653 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.MonthDayPattern);
1654 return false;
1655 }
1656 result.Month = raw.month;
1657 if ((order == 7 || order == 6) && result.calendar.IsValidDay(result.Year, result.Month, raw.GetNumber(0), result.era))
1658 {
1659 result.Day = raw.GetNumber(0);
1660 return true;
1661 }
1662 result.SetBadDateTimeFailure();
1663 return false;
1664 }
1665
1666 private static bool GetDayOfNM(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
1667 {
1668 if ((result.flags & ParseFlags.HaveDate) != 0)
1669 {
1670 result.SetBadDateTimeFailure();
1671 return false;
1672 }
1673 if (!GetMonthDayOrder(dtfi.MonthDayPattern, out var order))
1674 {
1675 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.MonthDayPattern);
1676 return false;
1677 }
1678 if (order == 6)
1679 {
1680 if (!GetYearMonthOrder(dtfi.YearMonthPattern, out var order2))
1681 {
1682 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.YearMonthPattern);
1683 return false;
1684 }
1685 if (order2 == 4)
1686 {
1687 if (!TryAdjustYear(ref result, raw.GetNumber(0), out var adjustedYear) || !SetDateYMD(ref result, adjustedYear, raw.month, 1))
1688 {
1689 result.SetBadDateTimeFailure();
1690 return false;
1691 }
1692 return true;
1693 }
1694 }
1695 GetDefaultYear(ref result, ref styles);
1696 if (!SetDateYMD(ref result, result.Year, raw.month, raw.GetNumber(0)))
1697 {
1698 result.SetBadDateTimeFailure();
1699 return false;
1700 }
1701 return true;
1702 }
1703
1704 private static bool GetDayOfMNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
1705 {
1706 if ((result.flags & ParseFlags.HaveDate) != 0)
1707 {
1708 result.SetBadDateTimeFailure();
1709 return false;
1710 }
1711 int number = raw.GetNumber(0);
1712 int number2 = raw.GetNumber(1);
1713 if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, out var order))
1714 {
1715 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
1716 return false;
1717 }
1718 int adjustedYear;
1719 switch (order)
1720 {
1721 case 1:
1722 if (TryAdjustYear(ref result, number2, out adjustedYear) && result.calendar.IsValidDay(adjustedYear, raw.month, number, result.era))
1723 {
1724 result.SetDate(adjustedYear, raw.month, number);
1725 result.flags |= ParseFlags.HaveDate;
1726 return true;
1727 }
1728 if (TryAdjustYear(ref result, number, out adjustedYear) && result.calendar.IsValidDay(adjustedYear, raw.month, number2, result.era))
1729 {
1730 result.SetDate(adjustedYear, raw.month, number2);
1731 result.flags |= ParseFlags.HaveDate;
1732 return true;
1733 }
1734 break;
1735 case 0:
1736 if (TryAdjustYear(ref result, number, out adjustedYear) && result.calendar.IsValidDay(adjustedYear, raw.month, number2, result.era))
1737 {
1738 result.SetDate(adjustedYear, raw.month, number2);
1739 result.flags |= ParseFlags.HaveDate;
1740 return true;
1741 }
1742 if (TryAdjustYear(ref result, number2, out adjustedYear) && result.calendar.IsValidDay(adjustedYear, raw.month, number, result.era))
1743 {
1744 result.SetDate(adjustedYear, raw.month, number);
1745 result.flags |= ParseFlags.HaveDate;
1746 return true;
1747 }
1748 break;
1749 case 2:
1750 if (TryAdjustYear(ref result, number2, out adjustedYear) && result.calendar.IsValidDay(adjustedYear, raw.month, number, result.era))
1751 {
1752 result.SetDate(adjustedYear, raw.month, number);
1753 result.flags |= ParseFlags.HaveDate;
1754 return true;
1755 }
1756 if (TryAdjustYear(ref result, number, out adjustedYear) && result.calendar.IsValidDay(adjustedYear, raw.month, number2, result.era))
1757 {
1758 result.SetDate(adjustedYear, raw.month, number2);
1759 result.flags |= ParseFlags.HaveDate;
1760 return true;
1761 }
1762 break;
1763 }
1764 result.SetBadDateTimeFailure();
1765 return false;
1766 }
1767
1768 private static bool GetDayOfYNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
1769 {
1770 if ((result.flags & ParseFlags.HaveDate) != 0)
1771 {
1772 result.SetBadDateTimeFailure();
1773 return false;
1774 }
1775 int number = raw.GetNumber(0);
1776 int number2 = raw.GetNumber(1);
1777 string shortDatePattern = dtfi.ShortDatePattern;
1778 if (GetYearMonthDayOrder(shortDatePattern, out var order) && order == 3)
1779 {
1780 if (SetDateYMD(ref result, raw.year, number2, number))
1781 {
1782 result.flags |= ParseFlags.HaveDate;
1783 return true;
1784 }
1785 }
1786 else if (SetDateYMD(ref result, raw.year, number, number2))
1787 {
1788 result.flags |= ParseFlags.HaveDate;
1789 return true;
1790 }
1791 result.SetBadDateTimeFailure();
1792 return false;
1793 }
1794
1795 private static bool GetDayOfNNY(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
1796 {
1797 if ((result.flags & ParseFlags.HaveDate) != 0)
1798 {
1799 result.SetBadDateTimeFailure();
1800 return false;
1801 }
1802 int number = raw.GetNumber(0);
1803 int number2 = raw.GetNumber(1);
1804 if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, out var order))
1805 {
1806 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
1807 return false;
1808 }
1809 if (order == 1 || order == 0)
1810 {
1811 if (SetDateYMD(ref result, raw.year, number, number2))
1812 {
1813 result.flags |= ParseFlags.HaveDate;
1814 return true;
1815 }
1816 }
1817 else if (SetDateYMD(ref result, raw.year, number2, number))
1818 {
1819 result.flags |= ParseFlags.HaveDate;
1820 return true;
1821 }
1822 result.SetBadDateTimeFailure();
1823 return false;
1824 }
1825
1826 private static bool GetDayOfYMN(ref DateTimeResult result, ref DateTimeRawInfo raw)
1827 {
1828 if ((result.flags & ParseFlags.HaveDate) != 0)
1829 {
1830 result.SetBadDateTimeFailure();
1831 return false;
1832 }
1833 if (SetDateYMD(ref result, raw.year, raw.month, raw.GetNumber(0)))
1834 {
1835 result.flags |= ParseFlags.HaveDate;
1836 return true;
1837 }
1838 result.SetBadDateTimeFailure();
1839 return false;
1840 }
1841
1842 private static bool GetDayOfYN(ref DateTimeResult result, ref DateTimeRawInfo raw)
1843 {
1844 if ((result.flags & ParseFlags.HaveDate) != 0)
1845 {
1846 result.SetBadDateTimeFailure();
1847 return false;
1848 }
1849 if (SetDateYMD(ref result, raw.year, raw.GetNumber(0), 1))
1850 {
1851 result.flags |= ParseFlags.HaveDate;
1852 return true;
1853 }
1854 result.SetBadDateTimeFailure();
1855 return false;
1856 }
1857
1858 private static bool GetDayOfYM(ref DateTimeResult result, ref DateTimeRawInfo raw)
1859 {
1860 if ((result.flags & ParseFlags.HaveDate) != 0)
1861 {
1862 result.SetBadDateTimeFailure();
1863 return false;
1864 }
1865 if (SetDateYMD(ref result, raw.year, raw.month, 1))
1866 {
1867 result.flags |= ParseFlags.HaveDate;
1868 return true;
1869 }
1870 result.SetBadDateTimeFailure();
1871 return false;
1872 }
1873
1874 private static void AdjustTimeMark(DateTimeFormatInfo dtfi, ref DateTimeRawInfo raw)
1875 {
1876 if (raw.timeMark == TM.NotSet && dtfi.AMDesignator != null && dtfi.PMDesignator != null)
1877 {
1878 if (dtfi.AMDesignator.Length == 0 && dtfi.PMDesignator.Length != 0)
1879 {
1880 raw.timeMark = TM.AM;
1881 }
1882 if (dtfi.PMDesignator.Length == 0 && dtfi.AMDesignator.Length != 0)
1883 {
1884 raw.timeMark = TM.PM;
1885 }
1886 }
1887 }
1888
1889 private static bool AdjustHour(ref int hour, TM timeMark)
1890 {
1891 switch (timeMark)
1892 {
1893 case TM.AM:
1894 if (hour < 0 || hour > 12)
1895 {
1896 return false;
1897 }
1898 hour = ((hour != 12) ? hour : 0);
1899 break;
1900 default:
1901 if (hour < 0 || hour > 23)
1902 {
1903 return false;
1904 }
1905 if (hour < 12)
1906 {
1907 hour += 12;
1908 }
1909 break;
1910 case TM.NotSet:
1911 break;
1912 }
1913 return true;
1914 }
1915
1916 private static bool GetTimeOfN(ref DateTimeResult result, ref DateTimeRawInfo raw)
1917 {
1918 if ((result.flags & ParseFlags.HaveTime) != 0)
1919 {
1920 result.SetBadDateTimeFailure();
1921 return false;
1922 }
1923 if (raw.timeMark == TM.NotSet)
1924 {
1925 result.SetBadDateTimeFailure();
1926 return false;
1927 }
1928 result.Hour = raw.GetNumber(0);
1929 result.flags |= ParseFlags.HaveTime;
1930 return true;
1931 }
1932
1933 private static bool GetTimeOfNN(ref DateTimeResult result, ref DateTimeRawInfo raw)
1934 {
1935 if ((result.flags & ParseFlags.HaveTime) != 0)
1936 {
1937 result.SetBadDateTimeFailure();
1938 return false;
1939 }
1940 result.Hour = raw.GetNumber(0);
1941 result.Minute = raw.GetNumber(1);
1942 result.flags |= ParseFlags.HaveTime;
1943 return true;
1944 }
1945
1946 private static bool GetTimeOfNNN(ref DateTimeResult result, ref DateTimeRawInfo raw)
1947 {
1948 if ((result.flags & ParseFlags.HaveTime) != 0)
1949 {
1950 result.SetBadDateTimeFailure();
1951 return false;
1952 }
1953 result.Hour = raw.GetNumber(0);
1954 result.Minute = raw.GetNumber(1);
1955 result.Second = raw.GetNumber(2);
1956 result.flags |= ParseFlags.HaveTime;
1957 return true;
1958 }
1959
1960 private static bool GetDateOfDSN(ref DateTimeResult result, ref DateTimeRawInfo raw)
1961 {
1962 if (raw.numCount != 1 || result.Day != -1)
1963 {
1964 result.SetBadDateTimeFailure();
1965 return false;
1966 }
1967 result.Day = raw.GetNumber(0);
1968 return true;
1969 }
1970
1971 private static bool GetDateOfNDS(ref DateTimeResult result, ref DateTimeRawInfo raw)
1972 {
1973 if (result.Month == -1)
1974 {
1975 result.SetBadDateTimeFailure();
1976 return false;
1977 }
1978 if (result.Year != -1)
1979 {
1980 result.SetBadDateTimeFailure();
1981 return false;
1982 }
1983 if (!TryAdjustYear(ref result, raw.GetNumber(0), out result.Year))
1984 {
1985 result.SetBadDateTimeFailure();
1986 return false;
1987 }
1988 result.Day = 1;
1989 return true;
1990 }
1991
1992 private static bool GetDateOfNNDS(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
1993 {
1994 if ((result.flags & ParseFlags.HaveYear) != 0)
1995 {
1996 if ((result.flags & ParseFlags.HaveMonth) == 0 && (result.flags & ParseFlags.HaveDay) == 0 && TryAdjustYear(ref result, raw.year, out result.Year) && SetDateYMD(ref result, result.Year, raw.GetNumber(0), raw.GetNumber(1)))
1997 {
1998 return true;
1999 }
2000 }
2001 else if ((result.flags & ParseFlags.HaveMonth) != 0 && (result.flags & ParseFlags.HaveYear) == 0 && (result.flags & ParseFlags.HaveDay) == 0)
2002 {
2003 if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, out var order))
2004 {
2005 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
2006 return false;
2007 }
2008 int adjustedYear;
2009 if (order == 0)
2010 {
2011 if (TryAdjustYear(ref result, raw.GetNumber(0), out adjustedYear) && SetDateYMD(ref result, adjustedYear, result.Month, raw.GetNumber(1)))
2012 {
2013 return true;
2014 }
2015 }
2016 else if (TryAdjustYear(ref result, raw.GetNumber(1), out adjustedYear) && SetDateYMD(ref result, adjustedYear, result.Month, raw.GetNumber(0)))
2017 {
2018 return true;
2019 }
2020 }
2021 result.SetBadDateTimeFailure();
2022 return false;
2023 }
2024
2025 private static bool ProcessDateTimeSuffix(ref DateTimeResult result, ref DateTimeRawInfo raw, ref DateTimeToken dtok)
2026 {
2027 switch (dtok.suffix)
2028 {
2029 case TokenType.SEP_YearSuff:
2030 if ((result.flags & ParseFlags.HaveYear) != 0)
2031 {
2032 return false;
2033 }
2034 result.flags |= ParseFlags.HaveYear;
2035 result.Year = (raw.year = dtok.num);
2036 break;
2037 case TokenType.SEP_MonthSuff:
2038 if ((result.flags & ParseFlags.HaveMonth) != 0)
2039 {
2040 return false;
2041 }
2042 result.flags |= ParseFlags.HaveMonth;
2043 result.Month = (raw.month = dtok.num);
2044 break;
2045 case TokenType.SEP_DaySuff:
2046 if ((result.flags & ParseFlags.HaveDay) != 0)
2047 {
2048 return false;
2049 }
2050 result.flags |= ParseFlags.HaveDay;
2051 result.Day = dtok.num;
2052 break;
2053 case TokenType.SEP_HourSuff:
2054 if ((result.flags & ParseFlags.HaveHour) != 0)
2055 {
2056 return false;
2057 }
2058 result.flags |= ParseFlags.HaveHour;
2059 result.Hour = dtok.num;
2060 break;
2061 case TokenType.SEP_MinuteSuff:
2062 if ((result.flags & ParseFlags.HaveMinute) != 0)
2063 {
2064 return false;
2065 }
2066 result.flags |= ParseFlags.HaveMinute;
2067 result.Minute = dtok.num;
2068 break;
2069 case TokenType.SEP_SecondSuff:
2070 if ((result.flags & ParseFlags.HaveSecond) != 0)
2071 {
2072 return false;
2073 }
2074 result.flags |= ParseFlags.HaveSecond;
2075 result.Second = dtok.num;
2076 break;
2077 }
2078 return true;
2079 }
2080
2081 internal static bool ProcessHebrewTerminalState(DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
2082 {
2083 switch (dps)
2084 {
2085 case DS.DX_MNN:
2086 raw.year = raw.GetNumber(1);
2087 if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, parsedMonthName: true))
2088 {
2089 result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar");
2090 return false;
2091 }
2092 if (!GetDayOfMNN(ref result, ref raw, dtfi))
2093 {
2094 return false;
2095 }
2096 break;
2097 case DS.DX_YMN:
2098 if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, parsedMonthName: true))
2099 {
2100 result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar");
2101 return false;
2102 }
2103 if (!GetDayOfYMN(ref result, ref raw))
2104 {
2105 return false;
2106 }
2107 break;
2108 case DS.DX_NNY:
2109 if (raw.year < 1000)
2110 {
2111 raw.year += 5000;
2112 }
2113 if (!GetDayOfNNY(ref result, ref raw, dtfi))
2114 {
2115 return false;
2116 }
2117 if (!dtfi.YearMonthAdjustment(ref result.Year, ref raw.month, parsedMonthName: true))
2118 {
2119 result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar");
2120 return false;
2121 }
2122 break;
2123 case DS.DX_MN:
2124 case DS.DX_NM:
2125 GetDefaultYear(ref result, ref styles);
2126 if (!dtfi.YearMonthAdjustment(ref result.Year, ref raw.month, parsedMonthName: true))
2127 {
2128 result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar");
2129 return false;
2130 }
2131 if (!GetHebrewDayOfNM(ref result, ref raw, dtfi))
2132 {
2133 return false;
2134 }
2135 break;
2136 case DS.DX_YM:
2137 if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, parsedMonthName: true))
2138 {
2139 result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar");
2140 return false;
2141 }
2142 if (!GetDayOfYM(ref result, ref raw))
2143 {
2144 return false;
2145 }
2146 break;
2147 case DS.TX_N:
2148 if (!GetTimeOfN(ref result, ref raw))
2149 {
2150 return false;
2151 }
2152 break;
2153 case DS.TX_NN:
2154 if (!GetTimeOfNN(ref result, ref raw))
2155 {
2156 return false;
2157 }
2158 break;
2159 case DS.TX_NNN:
2160 if (!GetTimeOfNNN(ref result, ref raw))
2161 {
2162 return false;
2163 }
2164 break;
2165 default:
2166 result.SetBadDateTimeFailure();
2167 return false;
2168 }
2169 if (dps > DS.ERROR)
2170 {
2171 raw.numCount = 0;
2172 }
2173 return true;
2174 }
2175
2176 internal static bool ProcessTerminalState(DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
2177 {
2178 bool flag = true;
2179 switch (dps)
2180 {
2181 case DS.DX_NN:
2182 flag = GetDayOfNN(ref result, ref styles, ref raw, dtfi);
2183 break;
2184 case DS.DX_NNN:
2185 flag = GetDayOfNNN(ref result, ref raw, dtfi);
2186 break;
2187 case DS.DX_MN:
2188 flag = GetDayOfMN(ref result, ref styles, ref raw, dtfi);
2189 break;
2190 case DS.DX_NM:
2191 flag = GetDayOfNM(ref result, ref styles, ref raw, dtfi);
2192 break;
2193 case DS.DX_MNN:
2194 flag = GetDayOfMNN(ref result, ref raw, dtfi);
2195 break;
2196 case DS.DX_DS:
2197 flag = true;
2198 break;
2199 case DS.DX_YNN:
2200 flag = GetDayOfYNN(ref result, ref raw, dtfi);
2201 break;
2202 case DS.DX_NNY:
2203 flag = GetDayOfNNY(ref result, ref raw, dtfi);
2204 break;
2205 case DS.DX_YMN:
2206 flag = GetDayOfYMN(ref result, ref raw);
2207 break;
2208 case DS.DX_YN:
2209 flag = GetDayOfYN(ref result, ref raw);
2210 break;
2211 case DS.DX_YM:
2212 flag = GetDayOfYM(ref result, ref raw);
2213 break;
2214 case DS.TX_N:
2215 flag = GetTimeOfN(ref result, ref raw);
2216 break;
2217 case DS.TX_NN:
2218 flag = GetTimeOfNN(ref result, ref raw);
2219 break;
2220 case DS.TX_NNN:
2221 flag = GetTimeOfNNN(ref result, ref raw);
2222 break;
2223 case DS.TX_TS:
2224 flag = true;
2225 break;
2226 case DS.DX_DSN:
2227 flag = GetDateOfDSN(ref result, ref raw);
2228 break;
2229 case DS.DX_NDS:
2230 flag = GetDateOfNDS(ref result, ref raw);
2231 break;
2232 case DS.DX_NNDS:
2233 flag = GetDateOfNNDS(ref result, ref raw, dtfi);
2234 break;
2235 }
2236 if (!flag)
2237 {
2238 return false;
2239 }
2240 if (dps > DS.ERROR)
2241 {
2242 raw.numCount = 0;
2243 }
2244 return true;
2245 }
2246
2248 {
2249 DateTimeResult result = default(DateTimeResult);
2250 result.Init(s);
2251 if (TryParse(s, dtfi, styles, ref result))
2252 {
2253 return result.parsedDate;
2254 }
2255 throw GetDateTimeParseException(ref result);
2256 }
2257
2259 {
2260 DateTimeResult result = default(DateTimeResult);
2261 result.Init(s);
2262 result.flags |= ParseFlags.CaptureOffset;
2263 if (TryParse(s, dtfi, styles, ref result))
2264 {
2265 offset = result.timeZoneOffset;
2266 return result.parsedDate;
2267 }
2268 throw GetDateTimeParseException(ref result);
2269 }
2270
2271 internal static bool TryParse(ReadOnlySpan<char> s, DateTimeFormatInfo dtfi, DateTimeStyles styles, out DateTime result)
2272 {
2273 DateTimeResult result2 = default(DateTimeResult);
2274 result2.Init(s);
2275 if (TryParse(s, dtfi, styles, ref result2))
2276 {
2277 result = result2.parsedDate;
2278 return true;
2279 }
2280 result = DateTime.MinValue;
2281 return false;
2282 }
2283
2284 internal static bool TryParse(ReadOnlySpan<char> s, DateTimeFormatInfo dtfi, DateTimeStyles styles, out DateTime result, out TimeSpan offset)
2285 {
2286 DateTimeResult result2 = default(DateTimeResult);
2287 result2.Init(s);
2288 result2.flags |= ParseFlags.CaptureOffset;
2289 if (TryParse(s, dtfi, styles, ref result2))
2290 {
2291 result = result2.parsedDate;
2292 offset = result2.timeZoneOffset;
2293 return true;
2294 }
2295 result = DateTime.MinValue;
2297 return false;
2298 }
2299
2300 internal unsafe static bool TryParse(ReadOnlySpan<char> s, DateTimeFormatInfo dtfi, DateTimeStyles styles, ref DateTimeResult result)
2301 {
2302 if (s.Length == 0)
2303 {
2304 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDateTime");
2305 return false;
2306 }
2307 DS dS = DS.BEGIN;
2308 bool flag = false;
2309 DateTimeToken dtok = default(DateTimeToken);
2310 dtok.suffix = TokenType.SEP_Unk;
2311 DateTimeRawInfo raw = default(DateTimeRawInfo);
2312 int* numberBuffer = stackalloc int[3];
2313 raw.Init(numberBuffer);
2314 raw.hasSameDateAndTimeSeparators = dtfi.DateSeparator.Equals(dtfi.TimeSeparator, StringComparison.Ordinal);
2315 result.calendar = dtfi.Calendar;
2316 result.era = 0;
2317 __DTString str = new __DTString(s, dtfi);
2318 str.GetNext();
2319 do
2320 {
2321 if (!Lex(dS, ref str, ref dtok, ref raw, ref result, ref dtfi, styles))
2322 {
2323 return false;
2324 }
2325 if (dtok.dtt == DTT.Unk)
2326 {
2327 continue;
2328 }
2329 if (dtok.suffix != TokenType.SEP_Unk)
2330 {
2331 if (!ProcessDateTimeSuffix(ref result, ref raw, ref dtok))
2332 {
2333 result.SetBadDateTimeFailure();
2334 return false;
2335 }
2336 dtok.suffix = TokenType.SEP_Unk;
2337 }
2338 if (dtok.dtt == DTT.NumLocalTimeMark)
2339 {
2340 if (dS == DS.D_YNd || dS == DS.D_YN)
2341 {
2342 return ParseISO8601(ref raw, ref str, styles, ref result);
2343 }
2344 result.SetBadDateTimeFailure();
2345 return false;
2346 }
2347 if (raw.hasSameDateAndTimeSeparators)
2348 {
2349 if (dtok.dtt == DTT.YearEnd || dtok.dtt == DTT.YearSpace || dtok.dtt == DTT.YearDateSep)
2350 {
2351 if (dS == DS.T_Nt)
2352 {
2353 dS = DS.D_Nd;
2354 }
2355 if (dS == DS.T_NNt)
2356 {
2357 dS = DS.D_NNd;
2358 }
2359 }
2360 bool flag2 = str.AtEnd();
2361 if (s_dateParsingStates[(int)dS][(int)dtok.dtt] == DS.ERROR || flag2)
2362 {
2363 switch (dtok.dtt)
2364 {
2365 case DTT.YearDateSep:
2366 dtok.dtt = (flag2 ? DTT.YearEnd : DTT.YearSpace);
2367 break;
2368 case DTT.NumDatesep:
2369 dtok.dtt = (flag2 ? DTT.NumEnd : DTT.NumSpace);
2370 break;
2371 case DTT.NumTimesep:
2372 dtok.dtt = (flag2 ? DTT.NumEnd : DTT.NumSpace);
2373 break;
2374 case DTT.MonthDatesep:
2375 dtok.dtt = (flag2 ? DTT.MonthEnd : DTT.MonthSpace);
2376 break;
2377 }
2378 }
2379 }
2380 dS = s_dateParsingStates[(int)dS][(int)dtok.dtt];
2381 if (dS == DS.ERROR)
2382 {
2383 result.SetBadDateTimeFailure();
2384 return false;
2385 }
2386 if (dS <= DS.ERROR)
2387 {
2388 continue;
2389 }
2390 if ((dtfi.FormatFlags & DateTimeFormatFlags.UseHebrewRule) != 0)
2391 {
2392 if (!ProcessHebrewTerminalState(dS, ref result, ref styles, ref raw, dtfi))
2393 {
2394 return false;
2395 }
2396 }
2397 else if (!ProcessTerminalState(dS, ref result, ref styles, ref raw, dtfi))
2398 {
2399 return false;
2400 }
2401 flag = true;
2402 dS = DS.BEGIN;
2403 }
2404 while (dtok.dtt != 0 && dtok.dtt != DTT.NumEnd && dtok.dtt != DTT.MonthEnd);
2405 if (!flag)
2406 {
2407 result.SetBadDateTimeFailure();
2408 return false;
2409 }
2410 AdjustTimeMark(dtfi, ref raw);
2411 if (!AdjustHour(ref result.Hour, raw.timeMark))
2412 {
2413 result.SetBadDateTimeFailure();
2414 return false;
2415 }
2416 bool bTimeOnly = result.Year == -1 && result.Month == -1 && result.Day == -1;
2417 if (!CheckDefaultDateTime(ref result, ref result.calendar, styles))
2418 {
2419 return false;
2420 }
2421 if (!result.calendar.TryToDateTime(result.Year, result.Month, result.Day, result.Hour, result.Minute, result.Second, 0, result.era, out var result2))
2422 {
2423 result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar");
2424 return false;
2425 }
2426 if (raw.fraction > 0.0 && !result2.TryAddTicks((long)Math.Round(raw.fraction * 10000000.0), out result2))
2427 {
2428 result.SetBadDateTimeFailure();
2429 return false;
2430 }
2431 if (raw.dayOfWeek != -1 && raw.dayOfWeek != (int)result.calendar.GetDayOfWeek(result2))
2432 {
2433 result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, "Format_BadDayOfWeek");
2434 return false;
2435 }
2436 result.parsedDate = result2;
2437 if (!DetermineTimeZoneAdjustments(ref result, styles, bTimeOnly))
2438 {
2439 return false;
2440 }
2441 return true;
2442 }
2443
2444 private static bool DetermineTimeZoneAdjustments(ref DateTimeResult result, DateTimeStyles styles, bool bTimeOnly)
2445 {
2446 if ((result.flags & ParseFlags.CaptureOffset) != 0)
2447 {
2448 return DateTimeOffsetTimeZonePostProcessing(ref result, styles);
2449 }
2450 long ticks = result.timeZoneOffset.Ticks;
2451 if (ticks < -504000000000L || ticks > 504000000000L)
2452 {
2453 result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, "Format_OffsetOutOfRange");
2454 return false;
2455 }
2456 if ((result.flags & ParseFlags.TimeZoneUsed) == 0)
2457 {
2458 if ((styles & DateTimeStyles.AssumeLocal) != 0)
2459 {
2460 if ((styles & DateTimeStyles.AdjustToUniversal) == 0)
2461 {
2462 result.parsedDate = DateTime.SpecifyKind(result.parsedDate, DateTimeKind.Local);
2463 return true;
2464 }
2465 result.flags |= ParseFlags.TimeZoneUsed;
2466 result.timeZoneOffset = TimeZoneInfo.GetLocalUtcOffset(result.parsedDate, TimeZoneInfoOptions.NoThrowOnInvalidTime);
2467 }
2468 else
2469 {
2470 if ((styles & DateTimeStyles.AssumeUniversal) == 0)
2471 {
2472 return true;
2473 }
2474 if ((styles & DateTimeStyles.AdjustToUniversal) != 0)
2475 {
2476 result.parsedDate = DateTime.SpecifyKind(result.parsedDate, DateTimeKind.Utc);
2477 return true;
2478 }
2479 result.flags |= ParseFlags.TimeZoneUsed;
2480 result.timeZoneOffset = TimeSpan.Zero;
2481 }
2482 }
2483 if ((styles & DateTimeStyles.RoundtripKind) != 0 && (result.flags & ParseFlags.TimeZoneUtc) != 0)
2484 {
2485 result.parsedDate = DateTime.SpecifyKind(result.parsedDate, DateTimeKind.Utc);
2486 return true;
2487 }
2488 if ((styles & DateTimeStyles.AdjustToUniversal) != 0)
2489 {
2490 return AdjustTimeZoneToUniversal(ref result);
2491 }
2492 return AdjustTimeZoneToLocal(ref result, bTimeOnly);
2493 }
2494
2496 {
2497 if ((result.flags & ParseFlags.TimeZoneUsed) == 0)
2498 {
2499 if ((styles & DateTimeStyles.AssumeUniversal) != 0)
2500 {
2501 result.timeZoneOffset = TimeSpan.Zero;
2502 }
2503 else
2504 {
2505 result.timeZoneOffset = TimeZoneInfo.GetLocalUtcOffset(result.parsedDate, TimeZoneInfoOptions.NoThrowOnInvalidTime);
2506 }
2507 }
2508 long ticks = result.timeZoneOffset.Ticks;
2509 long num = result.parsedDate.Ticks - ticks;
2510 if (num < 0 || num > 3155378975999999999L)
2511 {
2512 result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, "Format_UTCOutOfRange");
2513 return false;
2514 }
2515 if (ticks < -504000000000L || ticks > 504000000000L)
2516 {
2517 result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, "Format_OffsetOutOfRange");
2518 return false;
2519 }
2520 if ((styles & DateTimeStyles.AdjustToUniversal) != 0)
2521 {
2522 if ((result.flags & ParseFlags.TimeZoneUsed) == 0 && (styles & DateTimeStyles.AssumeUniversal) == 0)
2523 {
2524 bool result2 = AdjustTimeZoneToUniversal(ref result);
2525 result.timeZoneOffset = TimeSpan.Zero;
2526 return result2;
2527 }
2528 result.parsedDate = new DateTime(num, DateTimeKind.Utc);
2529 result.timeZoneOffset = TimeSpan.Zero;
2530 }
2531 return true;
2532 }
2533
2534 private static bool AdjustTimeZoneToUniversal(ref DateTimeResult result)
2535 {
2536 long ticks = result.parsedDate.Ticks;
2537 ticks -= result.timeZoneOffset.Ticks;
2538 if (ticks < 0)
2539 {
2540 ticks += 864000000000L;
2541 }
2542 if (ticks < 0 || ticks > 3155378975999999999L)
2543 {
2544 result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, "Format_DateOutOfRange");
2545 return false;
2546 }
2547 result.parsedDate = new DateTime(ticks, DateTimeKind.Utc);
2548 return true;
2549 }
2550
2551 private static bool AdjustTimeZoneToLocal(ref DateTimeResult result, bool bTimeOnly)
2552 {
2553 long ticks = result.parsedDate.Ticks;
2555 bool isAmbiguousLocalDst = false;
2556 if (ticks < 864000000000L)
2557 {
2558 ticks -= result.timeZoneOffset.Ticks;
2559 ticks += local.GetUtcOffset(bTimeOnly ? DateTime.Now : result.parsedDate, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
2560 if (ticks < 0)
2561 {
2562 ticks += 864000000000L;
2563 }
2564 }
2565 else
2566 {
2567 ticks -= result.timeZoneOffset.Ticks;
2568 if (ticks < 0 || ticks > 3155378975999999999L)
2569 {
2570 ticks += local.GetUtcOffset(result.parsedDate, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks;
2571 }
2572 else
2573 {
2574 DateTime time = new DateTime(ticks, DateTimeKind.Utc);
2575 ticks += TimeZoneInfo.GetUtcOffsetFromUtc(time, TimeZoneInfo.Local, out var _, out isAmbiguousLocalDst).Ticks;
2576 }
2577 }
2578 if (ticks < 0 || ticks > 3155378975999999999L)
2579 {
2580 result.parsedDate = DateTime.MinValue;
2581 result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, "Format_DateOutOfRange");
2582 return false;
2583 }
2584 result.parsedDate = new DateTime(ticks, DateTimeKind.Local, isAmbiguousLocalDst);
2585 return true;
2586 }
2587
2588 private static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, ref DateTimeResult result)
2589 {
2590 if (raw.year >= 0 && raw.GetNumber(0) >= 0)
2591 {
2592 raw.GetNumber(1);
2593 _ = 0;
2594 }
2595 str.Index--;
2596 int result2 = 0;
2597 double result3 = 0.0;
2598 str.SkipWhiteSpaces();
2599 if (!ParseDigits(ref str, 2, out var result4))
2600 {
2601 result.SetBadDateTimeFailure();
2602 return false;
2603 }
2604 str.SkipWhiteSpaces();
2605 if (!str.Match(':'))
2606 {
2607 result.SetBadDateTimeFailure();
2608 return false;
2609 }
2610 str.SkipWhiteSpaces();
2611 if (!ParseDigits(ref str, 2, out var result5))
2612 {
2613 result.SetBadDateTimeFailure();
2614 return false;
2615 }
2616 str.SkipWhiteSpaces();
2617 if (str.Match(':'))
2618 {
2619 str.SkipWhiteSpaces();
2620 if (!ParseDigits(ref str, 2, out result2))
2621 {
2622 result.SetBadDateTimeFailure();
2623 return false;
2624 }
2625 if (str.Match('.'))
2626 {
2627 if (!ParseFraction(ref str, out result3))
2628 {
2629 result.SetBadDateTimeFailure();
2630 return false;
2631 }
2632 str.Index--;
2633 }
2634 str.SkipWhiteSpaces();
2635 }
2636 if (str.GetNext())
2637 {
2638 switch (str.GetChar())
2639 {
2640 case '+':
2641 case '-':
2642 result.flags |= ParseFlags.TimeZoneUsed;
2643 if (!ParseTimeZone(ref str, ref result.timeZoneOffset))
2644 {
2645 result.SetBadDateTimeFailure();
2646 return false;
2647 }
2648 str.Index--;
2649 break;
2650 case 'Z':
2651 case 'z':
2652 result.flags |= ParseFlags.TimeZoneUsed;
2653 result.timeZoneOffset = TimeSpan.Zero;
2654 result.flags |= ParseFlags.TimeZoneUtc;
2655 break;
2656 default:
2657 str.Index--;
2658 break;
2659 }
2660 str.SkipWhiteSpaces();
2661 if (str.Match('#'))
2662 {
2663 if (!VerifyValidPunctuation(ref str))
2664 {
2665 result.SetBadDateTimeFailure();
2666 return false;
2667 }
2668 str.SkipWhiteSpaces();
2669 }
2670 if (str.Match('\0') && !VerifyValidPunctuation(ref str))
2671 {
2672 result.SetBadDateTimeFailure();
2673 return false;
2674 }
2675 if (str.GetNext())
2676 {
2677 result.SetBadDateTimeFailure();
2678 return false;
2679 }
2680 }
2681 Calendar defaultInstance = GregorianCalendar.GetDefaultInstance();
2682 if (!defaultInstance.TryToDateTime(raw.year, raw.GetNumber(0), raw.GetNumber(1), result4, result5, result2, 0, result.era, out var result6))
2683 {
2684 result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar");
2685 return false;
2686 }
2687 if (!result6.TryAddTicks((long)Math.Round(result3 * 10000000.0), out result6))
2688 {
2689 result.SetBadDateTimeFailure();
2690 return false;
2691 }
2692 result.parsedDate = result6;
2693 return DetermineTimeZoneAdjustments(ref result, styles, bTimeOnly: false);
2694 }
2695
2696 internal static bool MatchHebrewDigits(ref __DTString str, int digitLen, out int number)
2697 {
2698 number = 0;
2700 HebrewNumberParsingState hebrewNumberParsingState = HebrewNumberParsingState.ContinueParsing;
2701 while (hebrewNumberParsingState == HebrewNumberParsingState.ContinueParsing && str.GetNext())
2702 {
2703 hebrewNumberParsingState = HebrewNumber.ParseByChar(str.GetChar(), ref context);
2704 }
2705 if (hebrewNumberParsingState == HebrewNumberParsingState.FoundEndOfHebrewNumber)
2706 {
2707 number = context.result;
2708 return true;
2709 }
2710 return false;
2711 }
2712
2713 internal static bool ParseDigits(ref __DTString str, int digitLen, out int result)
2714 {
2715 if (digitLen == 1)
2716 {
2717 return ParseDigits(ref str, 1, 2, out result);
2718 }
2719 return ParseDigits(ref str, digitLen, digitLen, out result);
2720 }
2721
2722 internal static bool ParseDigits(ref __DTString str, int minDigitLen, int maxDigitLen, out int result)
2723 {
2724 int num = 0;
2725 int index = str.Index;
2726 int i;
2727 for (i = 0; i < maxDigitLen; i++)
2728 {
2729 if (!str.GetNextDigit())
2730 {
2731 str.Index--;
2732 break;
2733 }
2734 num = num * 10 + str.GetDigit();
2735 }
2736 result = num;
2737 if (i < minDigitLen)
2738 {
2739 str.Index = index;
2740 return false;
2741 }
2742 return true;
2743 }
2744
2745 private static bool ParseFractionExact(ref __DTString str, int maxDigitLen, ref double result)
2746 {
2747 if (!str.GetNextDigit())
2748 {
2749 str.Index--;
2750 return false;
2751 }
2752 result = str.GetDigit();
2753 int i;
2754 for (i = 1; i < maxDigitLen; i++)
2755 {
2756 if (!str.GetNextDigit())
2757 {
2758 str.Index--;
2759 break;
2760 }
2761 result = result * 10.0 + (double)str.GetDigit();
2762 }
2763 result /= TimeSpanParse.Pow10(i);
2764 return i == maxDigitLen;
2765 }
2766
2767 private static bool ParseSign(ref __DTString str, ref bool result)
2768 {
2769 if (!str.GetNext())
2770 {
2771 return false;
2772 }
2773 switch (str.GetChar())
2774 {
2775 case '+':
2776 result = true;
2777 return true;
2778 case '-':
2779 result = false;
2780 return true;
2781 default:
2782 return false;
2783 }
2784 }
2785
2786 private static bool ParseTimeZoneOffset(ref __DTString str, int len, ref TimeSpan result)
2787 {
2788 bool result2 = true;
2789 int result3 = 0;
2790 int result4;
2791 if ((uint)(len - 1) <= 1u)
2792 {
2793 if (!ParseSign(ref str, ref result2))
2794 {
2795 return false;
2796 }
2797 if (!ParseDigits(ref str, len, out result4))
2798 {
2799 return false;
2800 }
2801 }
2802 else
2803 {
2804 if (!ParseSign(ref str, ref result2))
2805 {
2806 return false;
2807 }
2808 if (!ParseDigits(ref str, 1, out result4))
2809 {
2810 return false;
2811 }
2812 if (str.Match(":"))
2813 {
2814 if (!ParseDigits(ref str, 2, out result3))
2815 {
2816 return false;
2817 }
2818 }
2819 else
2820 {
2821 str.Index--;
2822 if (!ParseDigits(ref str, 2, out result3))
2823 {
2824 return false;
2825 }
2826 }
2827 }
2828 if (result3 < 0 || result3 >= 60)
2829 {
2830 return false;
2831 }
2832 result = new TimeSpan(result4, result3, 0);
2833 if (!result2)
2834 {
2835 result = result.Negate();
2836 }
2837 return true;
2838 }
2839
2840 private static bool MatchAbbreviatedMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
2841 {
2842 int maxMatchStrLen = 0;
2843 result = -1;
2844 if (str.GetNext())
2845 {
2846 int num = ((dtfi.GetMonthName(13).Length == 0) ? 12 : 13);
2847 for (int i = 1; i <= num; i++)
2848 {
2849 string abbreviatedMonthName = dtfi.GetAbbreviatedMonthName(i);
2850 int matchLength = abbreviatedMonthName.Length;
2851 if ((dtfi.HasSpacesInMonthNames ? str.MatchSpecifiedWords(abbreviatedMonthName, checkWordBoundary: false, ref matchLength) : str.MatchSpecifiedWord(abbreviatedMonthName)) && matchLength > maxMatchStrLen)
2852 {
2853 maxMatchStrLen = matchLength;
2854 result = i;
2855 }
2856 }
2857 if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0)
2858 {
2859 int num2 = str.MatchLongestWords(dtfi.AbbreviatedMonthGenitiveNames, ref maxMatchStrLen);
2860 if (num2 >= 0)
2861 {
2862 result = num2 + 1;
2863 }
2864 }
2865 if ((dtfi.FormatFlags & DateTimeFormatFlags.UseLeapYearMonth) != 0)
2866 {
2867 int num3 = str.MatchLongestWords(dtfi.InternalGetLeapYearMonthNames(), ref maxMatchStrLen);
2868 if (num3 >= 0)
2869 {
2870 result = num3 + 1;
2871 }
2872 }
2873 }
2874 if (result > 0)
2875 {
2876 str.Index += maxMatchStrLen - 1;
2877 return true;
2878 }
2879 return false;
2880 }
2881
2882 private static bool MatchMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
2883 {
2884 int maxMatchStrLen = 0;
2885 result = -1;
2886 if (str.GetNext())
2887 {
2888 int num = ((dtfi.GetMonthName(13).Length == 0) ? 12 : 13);
2889 for (int i = 1; i <= num; i++)
2890 {
2891 string monthName = dtfi.GetMonthName(i);
2892 int matchLength = monthName.Length;
2893 if ((dtfi.HasSpacesInMonthNames ? str.MatchSpecifiedWords(monthName, checkWordBoundary: false, ref matchLength) : str.MatchSpecifiedWord(monthName)) && matchLength > maxMatchStrLen)
2894 {
2895 maxMatchStrLen = matchLength;
2896 result = i;
2897 }
2898 }
2899 if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0)
2900 {
2901 int num2 = str.MatchLongestWords(dtfi.MonthGenitiveNames, ref maxMatchStrLen);
2902 if (num2 >= 0)
2903 {
2904 result = num2 + 1;
2905 }
2906 }
2907 if ((dtfi.FormatFlags & DateTimeFormatFlags.UseLeapYearMonth) != 0)
2908 {
2909 int num3 = str.MatchLongestWords(dtfi.InternalGetLeapYearMonthNames(), ref maxMatchStrLen);
2910 if (num3 >= 0)
2911 {
2912 result = num3 + 1;
2913 }
2914 }
2915 }
2916 if (result > 0)
2917 {
2918 str.Index += maxMatchStrLen - 1;
2919 return true;
2920 }
2921 return false;
2922 }
2923
2924 private static bool MatchAbbreviatedDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
2925 {
2926 int num = 0;
2927 result = -1;
2928 if (str.GetNext())
2929 {
2930 for (DayOfWeek dayOfWeek = DayOfWeek.Sunday; dayOfWeek <= DayOfWeek.Saturday; dayOfWeek++)
2931 {
2932 string abbreviatedDayName = dtfi.GetAbbreviatedDayName(dayOfWeek);
2933 int matchLength = abbreviatedDayName.Length;
2934 if ((dtfi.HasSpacesInDayNames ? str.MatchSpecifiedWords(abbreviatedDayName, checkWordBoundary: false, ref matchLength) : str.MatchSpecifiedWord(abbreviatedDayName)) && matchLength > num)
2935 {
2936 num = matchLength;
2937 result = (int)dayOfWeek;
2938 }
2939 }
2940 }
2941 if (result >= 0)
2942 {
2943 str.Index += num - 1;
2944 return true;
2945 }
2946 return false;
2947 }
2948
2949 private static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
2950 {
2951 int num = 0;
2952 result = -1;
2953 if (str.GetNext())
2954 {
2955 for (DayOfWeek dayOfWeek = DayOfWeek.Sunday; dayOfWeek <= DayOfWeek.Saturday; dayOfWeek++)
2956 {
2957 string dayName = dtfi.GetDayName(dayOfWeek);
2958 int matchLength = dayName.Length;
2959 if ((dtfi.HasSpacesInDayNames ? str.MatchSpecifiedWords(dayName, checkWordBoundary: false, ref matchLength) : str.MatchSpecifiedWord(dayName)) && matchLength > num)
2960 {
2961 num = matchLength;
2962 result = (int)dayOfWeek;
2963 }
2964 }
2965 }
2966 if (result >= 0)
2967 {
2968 str.Index += num - 1;
2969 return true;
2970 }
2971 return false;
2972 }
2973
2974 private static bool MatchEraName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
2975 {
2976 if (str.GetNext())
2977 {
2978 int[] eras = dtfi.Calendar.Eras;
2979 if (eras != null)
2980 {
2981 for (int i = 0; i < eras.Length; i++)
2982 {
2983 string eraName = dtfi.GetEraName(eras[i]);
2984 if (str.MatchSpecifiedWord(eraName))
2985 {
2986 str.Index += eraName.Length - 1;
2987 result = eras[i];
2988 return true;
2989 }
2990 eraName = dtfi.GetAbbreviatedEraName(eras[i]);
2991 if (str.MatchSpecifiedWord(eraName))
2992 {
2993 str.Index += eraName.Length - 1;
2994 result = eras[i];
2995 return true;
2996 }
2997 }
2998 }
2999 }
3000 return false;
3001 }
3002
3003 private static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result)
3004 {
3005 result = TM.NotSet;
3006 if (dtfi.AMDesignator.Length == 0)
3007 {
3008 result = TM.AM;
3009 }
3010 if (dtfi.PMDesignator.Length == 0)
3011 {
3012 result = TM.PM;
3013 }
3014 if (str.GetNext())
3015 {
3016 string aMDesignator = dtfi.AMDesignator;
3017 if (aMDesignator.Length > 0 && str.MatchSpecifiedWord(aMDesignator))
3018 {
3019 str.Index += aMDesignator.Length - 1;
3020 result = TM.AM;
3021 return true;
3022 }
3023 aMDesignator = dtfi.PMDesignator;
3024 if (aMDesignator.Length > 0 && str.MatchSpecifiedWord(aMDesignator))
3025 {
3026 str.Index += aMDesignator.Length - 1;
3027 result = TM.PM;
3028 return true;
3029 }
3030 str.Index--;
3031 }
3032 if (result != TM.NotSet)
3033 {
3034 return true;
3035 }
3036 return false;
3037 }
3038
3039 private static bool MatchAbbreviatedTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result)
3040 {
3041 if (str.GetNext())
3042 {
3043 string aMDesignator = dtfi.AMDesignator;
3044 if (aMDesignator.Length > 0 && str.GetChar() == aMDesignator[0])
3045 {
3046 result = TM.AM;
3047 return true;
3048 }
3049 string pMDesignator = dtfi.PMDesignator;
3050 if (pMDesignator.Length > 0 && str.GetChar() == pMDesignator[0])
3051 {
3052 result = TM.PM;
3053 return true;
3054 }
3055 }
3056 return false;
3057 }
3058
3059 private static bool CheckNewValue(ref int currentValue, int newValue, char patternChar, ref DateTimeResult result)
3060 {
3061 if (currentValue == -1)
3062 {
3063 currentValue = newValue;
3064 return true;
3065 }
3066 if (newValue != currentValue)
3067 {
3068 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", patternChar);
3069 return false;
3070 }
3071 return true;
3072 }
3073
3074 private static DateTime GetDateTimeNow(ref DateTimeResult result, ref DateTimeStyles styles)
3075 {
3076 if ((result.flags & ParseFlags.CaptureOffset) != 0)
3077 {
3078 if ((result.flags & ParseFlags.TimeZoneUsed) != 0)
3079 {
3080 return new DateTime(DateTime.UtcNow.Ticks + result.timeZoneOffset.Ticks, DateTimeKind.Unspecified);
3081 }
3082 if ((styles & DateTimeStyles.AssumeUniversal) != 0)
3083 {
3084 return DateTime.UtcNow;
3085 }
3086 }
3087 return DateTime.Now;
3088 }
3089
3090 private static bool CheckDefaultDateTime(ref DateTimeResult result, ref Calendar cal, DateTimeStyles styles)
3091 {
3092 if ((result.flags & ParseFlags.CaptureOffset) != 0 && (result.Month != -1 || result.Day != -1) && (result.Year == -1 || (result.flags & ParseFlags.YearDefault) != 0) && (result.flags & ParseFlags.TimeZoneUsed) != 0)
3093 {
3094 result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, "Format_MissingIncompleteDate");
3095 return false;
3096 }
3097 if (result.Year == -1 || result.Month == -1 || result.Day == -1)
3098 {
3099 DateTime dateTimeNow = GetDateTimeNow(ref result, ref styles);
3100 if (result.Month == -1 && result.Day == -1)
3101 {
3102 if (result.Year == -1)
3103 {
3104 if ((styles & DateTimeStyles.NoCurrentDateDefault) != 0)
3105 {
3107 result.Year = (result.Month = (result.Day = 1));
3108 }
3109 else
3110 {
3111 result.Year = cal.GetYear(dateTimeNow);
3112 result.Month = cal.GetMonth(dateTimeNow);
3113 result.Day = cal.GetDayOfMonth(dateTimeNow);
3114 }
3115 }
3116 else
3117 {
3118 result.Month = 1;
3119 result.Day = 1;
3120 }
3121 }
3122 else
3123 {
3124 if (result.Year == -1)
3125 {
3126 result.Year = cal.GetYear(dateTimeNow);
3127 }
3128 if (result.Month == -1)
3129 {
3130 result.Month = 1;
3131 }
3132 if (result.Day == -1)
3133 {
3134 result.Day = 1;
3135 }
3136 }
3137 }
3138 if (result.Hour == -1)
3139 {
3140 result.Hour = 0;
3141 }
3142 if (result.Minute == -1)
3143 {
3144 result.Minute = 0;
3145 }
3146 if (result.Second == -1)
3147 {
3148 result.Second = 0;
3149 }
3150 if (result.era == -1)
3151 {
3152 result.era = 0;
3153 }
3154 return true;
3155 }
3156
3157 private static string ExpandPredefinedFormat(ReadOnlySpan<char> format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
3158 {
3159 switch (format[0])
3160 {
3161 case 'O':
3162 case 'o':
3163 case 's':
3164 ConfigureFormatOS(ref dtfi, ref parseInfo);
3165 break;
3166 case 'R':
3167 case 'r':
3168 ConfigureFormatR(ref dtfi, ref parseInfo, ref result);
3169 break;
3170 case 'u':
3171 parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
3173 if ((result.flags & ParseFlags.CaptureOffset) != 0)
3174 {
3175 result.flags |= ParseFlags.UtcSortPattern;
3176 }
3177 break;
3178 case 'U':
3179 parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
3180 result.flags |= ParseFlags.TimeZoneUsed;
3181 result.timeZoneOffset = new TimeSpan(0L);
3182 result.flags |= ParseFlags.TimeZoneUtc;
3183 if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
3184 {
3185 dtfi = (DateTimeFormatInfo)dtfi.Clone();
3186 dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
3187 }
3188 break;
3189 }
3190 return DateTimeFormat.GetRealFormat(format, dtfi);
3191 }
3192
3193 [MethodImpl(MethodImplOptions.AggressiveInlining)]
3195 {
3197 {
3198 return false;
3199 }
3200 if (str.m_current != "å…ƒ"[0])
3201 {
3202 str.Index--;
3203 return false;
3204 }
3205 return true;
3206 }
3207
3208 private static void ConfigureFormatR(ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
3209 {
3210 parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
3212 if ((result.flags & ParseFlags.CaptureOffset) != 0)
3213 {
3214 result.flags |= ParseFlags.Rfc1123Pattern;
3215 }
3216 }
3217
3218 private static void ConfigureFormatOS(ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo)
3219 {
3220 parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
3222 }
3223
3224 private static bool ParseByFormat(ref __DTString str, ref __DTString format, ref ParsingInfo parseInfo, DateTimeFormatInfo dtfi, ref DateTimeResult result)
3225 {
3226 int result2 = 0;
3227 int result3 = 0;
3228 int result4 = 0;
3229 int result5 = 0;
3230 int result6 = 0;
3231 int result7 = 0;
3232 int result8 = 0;
3233 double result9 = 0.0;
3234 TM result10 = TM.AM;
3235 char @char = format.GetChar();
3236 switch (@char)
3237 {
3238 case 'y':
3239 {
3240 int repeatCount = format.GetRepeatCount();
3241 bool flag;
3242 if (ParseJapaneseEraStart(ref str, dtfi))
3243 {
3244 result2 = 1;
3245 flag = true;
3246 }
3247 else if (dtfi.HasForceTwoDigitYears)
3248 {
3249 flag = ParseDigits(ref str, 1, 4, out result2);
3250 }
3251 else
3252 {
3253 if (repeatCount <= 2)
3254 {
3255 parseInfo.fUseTwoDigitYear = true;
3256 }
3257 flag = ParseDigits(ref str, repeatCount, out result2);
3258 }
3259 if (!flag && parseInfo.fCustomNumberParser)
3260 {
3261 flag = parseInfo.parseNumberDelegate(ref str, repeatCount, out result2);
3262 }
3263 if (!flag)
3264 {
3265 result.SetBadDateTimeFailure();
3266 return false;
3267 }
3268 if (!CheckNewValue(ref result.Year, result2, @char, ref result))
3269 {
3270 return false;
3271 }
3272 break;
3273 }
3274 case 'M':
3275 {
3276 int repeatCount = format.GetRepeatCount();
3277 if (repeatCount <= 2)
3278 {
3279 if (!ParseDigits(ref str, repeatCount, out result3) && (!parseInfo.fCustomNumberParser || !parseInfo.parseNumberDelegate(ref str, repeatCount, out result3)))
3280 {
3281 result.SetBadDateTimeFailure();
3282 return false;
3283 }
3284 }
3285 else
3286 {
3287 if (repeatCount == 3)
3288 {
3289 if (!MatchAbbreviatedMonthName(ref str, dtfi, ref result3))
3290 {
3291 result.SetBadDateTimeFailure();
3292 return false;
3293 }
3294 }
3295 else if (!MatchMonthName(ref str, dtfi, ref result3))
3296 {
3297 result.SetBadDateTimeFailure();
3298 return false;
3299 }
3300 result.flags |= ParseFlags.ParsedMonthName;
3301 }
3302 if (!CheckNewValue(ref result.Month, result3, @char, ref result))
3303 {
3304 return false;
3305 }
3306 break;
3307 }
3308 case 'd':
3309 {
3310 int repeatCount = format.GetRepeatCount();
3311 if (repeatCount <= 2)
3312 {
3313 if (!ParseDigits(ref str, repeatCount, out result4) && (!parseInfo.fCustomNumberParser || !parseInfo.parseNumberDelegate(ref str, repeatCount, out result4)))
3314 {
3315 result.SetBadDateTimeFailure();
3316 return false;
3317 }
3318 if (!CheckNewValue(ref result.Day, result4, @char, ref result))
3319 {
3320 return false;
3321 }
3322 break;
3323 }
3324 if (repeatCount == 3)
3325 {
3326 if (!MatchAbbreviatedDayName(ref str, dtfi, ref result5))
3327 {
3328 result.SetBadDateTimeFailure();
3329 return false;
3330 }
3331 }
3332 else if (!MatchDayName(ref str, dtfi, ref result5))
3333 {
3334 result.SetBadDateTimeFailure();
3335 return false;
3336 }
3337 if (!CheckNewValue(ref parseInfo.dayOfWeek, result5, @char, ref result))
3338 {
3339 return false;
3340 }
3341 break;
3342 }
3343 case 'g':
3344 format.GetRepeatCount();
3345 if (!MatchEraName(ref str, dtfi, ref result.era))
3346 {
3347 result.SetBadDateTimeFailure();
3348 return false;
3349 }
3350 break;
3351 case 'h':
3352 {
3353 parseInfo.fUseHour12 = true;
3354 int repeatCount = format.GetRepeatCount();
3355 if (!ParseDigits(ref str, (repeatCount < 2) ? 1 : 2, out result6))
3356 {
3357 result.SetBadDateTimeFailure();
3358 return false;
3359 }
3360 if (!CheckNewValue(ref result.Hour, result6, @char, ref result))
3361 {
3362 return false;
3363 }
3364 break;
3365 }
3366 case 'H':
3367 {
3368 int repeatCount = format.GetRepeatCount();
3369 if (!ParseDigits(ref str, (repeatCount < 2) ? 1 : 2, out result6))
3370 {
3371 result.SetBadDateTimeFailure();
3372 return false;
3373 }
3374 if (!CheckNewValue(ref result.Hour, result6, @char, ref result))
3375 {
3376 return false;
3377 }
3378 break;
3379 }
3380 case 'm':
3381 {
3382 int repeatCount = format.GetRepeatCount();
3383 if (!ParseDigits(ref str, (repeatCount < 2) ? 1 : 2, out result7))
3384 {
3385 result.SetBadDateTimeFailure();
3386 return false;
3387 }
3388 if (!CheckNewValue(ref result.Minute, result7, @char, ref result))
3389 {
3390 return false;
3391 }
3392 break;
3393 }
3394 case 's':
3395 {
3396 int repeatCount = format.GetRepeatCount();
3397 if (!ParseDigits(ref str, (repeatCount < 2) ? 1 : 2, out result8))
3398 {
3399 result.SetBadDateTimeFailure();
3400 return false;
3401 }
3402 if (!CheckNewValue(ref result.Second, result8, @char, ref result))
3403 {
3404 return false;
3405 }
3406 break;
3407 }
3408 case 'F':
3409 case 'f':
3410 {
3411 int repeatCount = format.GetRepeatCount();
3412 if (repeatCount <= 7)
3413 {
3414 if (!ParseFractionExact(ref str, repeatCount, ref result9) && @char == 'f')
3415 {
3416 result.SetBadDateTimeFailure();
3417 return false;
3418 }
3419 if (result.fraction < 0.0)
3420 {
3421 result.fraction = result9;
3422 }
3423 else if (result9 != result.fraction)
3424 {
3425 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", @char);
3426 return false;
3427 }
3428 break;
3429 }
3430 result.SetBadDateTimeFailure();
3431 return false;
3432 }
3433 case 't':
3434 {
3435 int repeatCount = format.GetRepeatCount();
3436 if (repeatCount == 1)
3437 {
3438 if (!MatchAbbreviatedTimeMark(ref str, dtfi, ref result10))
3439 {
3440 result.SetBadDateTimeFailure();
3441 return false;
3442 }
3443 }
3444 else if (!MatchTimeMark(ref str, dtfi, ref result10))
3445 {
3446 result.SetBadDateTimeFailure();
3447 return false;
3448 }
3449 if (parseInfo.timeMark == TM.NotSet)
3450 {
3451 parseInfo.timeMark = result10;
3452 }
3453 else if (parseInfo.timeMark != result10)
3454 {
3455 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", @char);
3456 return false;
3457 }
3458 break;
3459 }
3460 case 'z':
3461 {
3462 int repeatCount = format.GetRepeatCount();
3463 TimeSpan result11 = new TimeSpan(0L);
3464 if (!ParseTimeZoneOffset(ref str, repeatCount, ref result11))
3465 {
3466 result.SetBadDateTimeFailure();
3467 return false;
3468 }
3469 if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && result11 != result.timeZoneOffset)
3470 {
3471 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", 'z');
3472 return false;
3473 }
3474 result.timeZoneOffset = result11;
3475 result.flags |= ParseFlags.TimeZoneUsed;
3476 break;
3477 }
3478 case 'Z':
3479 if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && result.timeZoneOffset != TimeSpan.Zero)
3480 {
3481 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", 'Z');
3482 return false;
3483 }
3484 result.flags |= ParseFlags.TimeZoneUsed;
3485 result.timeZoneOffset = new TimeSpan(0L);
3486 result.flags |= ParseFlags.TimeZoneUtc;
3487 str.Index++;
3488 if (!GetTimeZoneName(ref str))
3489 {
3490 result.SetBadDateTimeFailure();
3491 return false;
3492 }
3493 str.Index--;
3494 break;
3495 case 'K':
3496 if (str.Match('Z'))
3497 {
3498 if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && result.timeZoneOffset != TimeSpan.Zero)
3499 {
3500 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", 'K');
3501 return false;
3502 }
3503 result.flags |= ParseFlags.TimeZoneUsed;
3504 result.timeZoneOffset = new TimeSpan(0L);
3505 result.flags |= ParseFlags.TimeZoneUtc;
3506 }
3507 else if (str.Match('+') || str.Match('-'))
3508 {
3509 str.Index--;
3510 TimeSpan result12 = new TimeSpan(0L);
3511 if (!ParseTimeZoneOffset(ref str, 3, ref result12))
3512 {
3513 result.SetBadDateTimeFailure();
3514 return false;
3515 }
3516 if ((result.flags & ParseFlags.TimeZoneUsed) != 0 && result12 != result.timeZoneOffset)
3517 {
3518 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_RepeatDateTimePattern", 'K');
3519 return false;
3520 }
3521 result.timeZoneOffset = result12;
3522 result.flags |= ParseFlags.TimeZoneUsed;
3523 }
3524 break;
3525 case ':':
3526 if (((dtfi.TimeSeparator.Length > 1 && dtfi.TimeSeparator[0] == ':') || !str.Match(':')) && !str.Match(dtfi.TimeSeparator))
3527 {
3528 result.SetBadDateTimeFailure();
3529 return false;
3530 }
3531 break;
3532 case '/':
3533 if (((dtfi.DateSeparator.Length > 1 && dtfi.DateSeparator[0] == '/') || !str.Match('/')) && !str.Match(dtfi.DateSeparator))
3534 {
3535 result.SetBadDateTimeFailure();
3536 return false;
3537 }
3538 break;
3539 case '"':
3540 case '\'':
3541 {
3542 StringBuilder stringBuilder = StringBuilderCache.Acquire();
3543 if (!TryParseQuoteString(format.Value, format.Index, stringBuilder, out var repeatCount))
3544 {
3545 result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadQuote", @char);
3546 StringBuilderCache.Release(stringBuilder);
3547 return false;
3548 }
3549 format.Index += repeatCount - 1;
3550 string stringAndRelease = StringBuilderCache.GetStringAndRelease(stringBuilder);
3551 for (int i = 0; i < stringAndRelease.Length; i++)
3552 {
3553 if (stringAndRelease[i] == ' ' && parseInfo.fAllowInnerWhite)
3554 {
3555 str.SkipWhiteSpaces();
3556 }
3557 else if (!str.Match(stringAndRelease[i]))
3558 {
3559 result.SetBadDateTimeFailure();
3560 return false;
3561 }
3562 }
3563 if ((result.flags & ParseFlags.CaptureOffset) != 0 && (((result.flags & ParseFlags.Rfc1123Pattern) != 0 && stringAndRelease == "GMT") || ((result.flags & ParseFlags.UtcSortPattern) != 0 && stringAndRelease == "Z")))
3564 {
3565 result.flags |= ParseFlags.TimeZoneUsed;
3566 result.timeZoneOffset = TimeSpan.Zero;
3567 }
3568 break;
3569 }
3570 case '%':
3571 if (format.Index >= format.Value.Length - 1 || format.Value[format.Index + 1] == '%')
3572 {
3573 result.SetBadFormatSpecifierFailure(format.Value);
3574 return false;
3575 }
3576 break;
3577 case '\\':
3578 if (format.GetNext())
3579 {
3580 if (!str.Match(format.GetChar()))
3581 {
3582 result.SetBadDateTimeFailure();
3583 return false;
3584 }
3585 break;
3586 }
3587 result.SetBadFormatSpecifierFailure(format.Value);
3588 return false;
3589 case '.':
3590 if (!str.Match(@char))
3591 {
3592 if (!format.GetNext() || !format.Match('F'))
3593 {
3594 result.SetBadDateTimeFailure();
3595 return false;
3596 }
3597 format.GetRepeatCount();
3598 }
3599 break;
3600 default:
3601 if (@char == ' ')
3602 {
3603 if (!parseInfo.fAllowInnerWhite && !str.Match(@char))
3604 {
3605 if (parseInfo.fAllowTrailingWhite && format.GetNext() && ParseByFormat(ref str, ref format, ref parseInfo, dtfi, ref result))
3606 {
3607 return true;
3608 }
3609 result.SetBadDateTimeFailure();
3610 return false;
3611 }
3612 }
3613 else if (format.MatchSpecifiedWord("GMT"))
3614 {
3615 format.Index += "GMT".Length - 1;
3616 result.flags |= ParseFlags.TimeZoneUsed;
3617 result.timeZoneOffset = TimeSpan.Zero;
3618 if (!str.Match("GMT"))
3619 {
3620 result.SetBadDateTimeFailure();
3621 return false;
3622 }
3623 }
3624 else if (!str.Match(@char))
3625 {
3626 result.SetBadDateTimeFailure();
3627 return false;
3628 }
3629 break;
3630 }
3631 return true;
3632 }
3633
3634 internal static bool TryParseQuoteString(ReadOnlySpan<char> format, int pos, StringBuilder result, out int returnValue)
3635 {
3636 returnValue = 0;
3637 int length = format.Length;
3638 int num = pos;
3639 char c = format[pos++];
3640 bool flag = false;
3641 while (pos < length)
3642 {
3643 char c2 = format[pos++];
3644 if (c2 == c)
3645 {
3646 flag = true;
3647 break;
3648 }
3649 if (c2 == '\\')
3650 {
3651 if (pos >= length)
3652 {
3653 return false;
3654 }
3655 result.Append(format[pos++]);
3656 }
3657 else
3658 {
3659 result.Append(c2);
3660 }
3661 }
3662 if (!flag)
3663 {
3664 return false;
3665 }
3666 returnValue = pos - num;
3667 return true;
3668 }
3669
3671 {
3672 ParsingInfo parseInfo = default(ParsingInfo);
3673 parseInfo.Init();
3674 parseInfo.calendar = dtfi.Calendar;
3675 parseInfo.fAllowInnerWhite = (styles & DateTimeStyles.AllowInnerWhite) != 0;
3676 parseInfo.fAllowTrailingWhite = (styles & DateTimeStyles.AllowTrailingWhite) != 0;
3677 if (formatParam.Length == 1)
3678 {
3679 char c = formatParam[0];
3680 if (styles == DateTimeStyles.None)
3681 {
3682 switch (c)
3683 {
3684 case 'R':
3685 case 'r':
3686 ConfigureFormatR(ref dtfi, ref parseInfo, ref result);
3687 return ParseFormatR(s, ref parseInfo, ref result);
3688 case 'O':
3689 case 'o':
3690 ConfigureFormatOS(ref dtfi, ref parseInfo);
3691 return ParseFormatO(s, ref result);
3692 }
3693 }
3694 if ((result.flags & ParseFlags.CaptureOffset) != 0 && c == 'U')
3695 {
3696 result.SetBadFormatSpecifierFailure(formatParam);
3697 return false;
3698 }
3699 formatParam = ExpandPredefinedFormat(formatParam, ref dtfi, ref parseInfo, ref result);
3700 }
3701 result.calendar = parseInfo.calendar;
3702 if (parseInfo.calendar.ID == CalendarId.HEBREW)
3703 {
3704 parseInfo.parseNumberDelegate = s_hebrewNumberParser;
3705 parseInfo.fCustomNumberParser = true;
3706 }
3707 result.Hour = (result.Minute = (result.Second = -1));
3708 __DTString format = new __DTString(formatParam, dtfi, checkDigitToken: false);
3709 __DTString str = new __DTString(s, dtfi, checkDigitToken: false);
3710 if (parseInfo.fAllowTrailingWhite)
3711 {
3712 format.TrimTail();
3713 format.RemoveTrailingInQuoteSpaces();
3714 str.TrimTail();
3715 }
3716 if ((styles & DateTimeStyles.AllowLeadingWhite) != 0)
3717 {
3718 format.SkipWhiteSpaces();
3719 format.RemoveLeadingInQuoteSpaces();
3720 str.SkipWhiteSpaces();
3721 }
3722 while (format.GetNext())
3723 {
3724 if (parseInfo.fAllowInnerWhite)
3725 {
3726 str.SkipWhiteSpaces();
3727 }
3728 if (!ParseByFormat(ref str, ref format, ref parseInfo, dtfi, ref result))
3729 {
3730 return false;
3731 }
3732 }
3733 if (str.Index < str.Value.Length - 1)
3734 {
3735 result.SetBadDateTimeFailure();
3736 return false;
3737 }
3738 if (parseInfo.fUseTwoDigitYear && (dtfi.FormatFlags & DateTimeFormatFlags.UseHebrewRule) == 0)
3739 {
3740 if (result.Year >= 100)
3741 {
3742 result.SetBadDateTimeFailure();
3743 return false;
3744 }
3745 try
3746 {
3747 result.Year = parseInfo.calendar.ToFourDigitYear(result.Year);
3748 }
3750 {
3751 result.SetBadDateTimeFailure();
3752 return false;
3753 }
3754 }
3755 if (parseInfo.fUseHour12)
3756 {
3757 if (parseInfo.timeMark == TM.NotSet)
3758 {
3759 parseInfo.timeMark = TM.AM;
3760 }
3761 if (result.Hour > 12)
3762 {
3763 result.SetBadDateTimeFailure();
3764 return false;
3765 }
3766 if (parseInfo.timeMark == TM.AM)
3767 {
3768 if (result.Hour == 12)
3769 {
3770 result.Hour = 0;
3771 }
3772 }
3773 else
3774 {
3775 result.Hour = ((result.Hour == 12) ? 12 : (result.Hour + 12));
3776 }
3777 }
3778 else if ((parseInfo.timeMark == TM.AM && result.Hour >= 12) || (parseInfo.timeMark == TM.PM && result.Hour < 12))
3779 {
3780 result.SetBadDateTimeFailure();
3781 return false;
3782 }
3783 bool flag = result.Year == -1 && result.Month == -1 && result.Day == -1;
3784 if (!CheckDefaultDateTime(ref result, ref parseInfo.calendar, styles))
3785 {
3786 return false;
3787 }
3788 if (!flag && dtfi.HasYearMonthAdjustment && !dtfi.YearMonthAdjustment(ref result.Year, ref result.Month, (result.flags & ParseFlags.ParsedMonthName) != 0))
3789 {
3790 result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar");
3791 return false;
3792 }
3793 if (!parseInfo.calendar.TryToDateTime(result.Year, result.Month, result.Day, result.Hour, result.Minute, result.Second, 0, result.era, out result.parsedDate))
3794 {
3795 result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar");
3796 return false;
3797 }
3798 if (result.fraction > 0.0 && !result.parsedDate.TryAddTicks((long)Math.Round(result.fraction * 10000000.0), out result.parsedDate))
3799 {
3800 result.SetBadDateTimeFailure();
3801 return false;
3802 }
3803 if (parseInfo.dayOfWeek != -1 && parseInfo.dayOfWeek != (int)parseInfo.calendar.GetDayOfWeek(result.parsedDate))
3804 {
3805 result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, "Format_BadDayOfWeek");
3806 return false;
3807 }
3808 return DetermineTimeZoneAdjustments(ref result, styles, flag);
3809 }
3810
3811 private static bool ParseFormatR(ReadOnlySpan<char> source, ref ParsingInfo parseInfo, ref DateTimeResult result)
3812 {
3813 if (source.Length != 29)
3814 {
3815 result.SetBadDateTimeFailure();
3816 return false;
3817 }
3818 uint num = source[0];
3819 uint num2 = source[1];
3820 uint num3 = source[2];
3821 uint num4 = source[3];
3822 if ((num | num2 | num3 | num4) > 127)
3823 {
3824 result.SetBadDateTimeFailure();
3825 return false;
3826 }
3827 DayOfWeek dayOfWeek;
3828 switch ((num << 24) | (num2 << 16) | (num3 << 8) | num4 | 0x20202000)
3829 {
3830 case 1937075756u:
3831 dayOfWeek = DayOfWeek.Sunday;
3832 break;
3833 case 1836019244u:
3834 dayOfWeek = DayOfWeek.Monday;
3835 break;
3836 case 1953850668u:
3837 dayOfWeek = DayOfWeek.Tuesday;
3838 break;
3839 case 2003133484u:
3840 dayOfWeek = DayOfWeek.Wednesday;
3841 break;
3842 case 1953002796u:
3843 dayOfWeek = DayOfWeek.Thursday;
3844 break;
3845 case 1718774060u:
3846 dayOfWeek = DayOfWeek.Friday;
3847 break;
3848 case 1935766572u:
3849 dayOfWeek = DayOfWeek.Saturday;
3850 break;
3851 default:
3852 result.SetBadDateTimeFailure();
3853 return false;
3854 }
3855 if (source[4] != ' ')
3856 {
3857 result.SetBadDateTimeFailure();
3858 return false;
3859 }
3860 uint num5 = (uint)(source[5] - 48);
3861 uint num6 = (uint)(source[6] - 48);
3862 if (num5 > 9 || num6 > 9)
3863 {
3864 result.SetBadDateTimeFailure();
3865 return false;
3866 }
3867 int day = (int)(num5 * 10 + num6);
3868 if (source[7] != ' ')
3869 {
3870 result.SetBadDateTimeFailure();
3871 return false;
3872 }
3873 uint num7 = source[8];
3874 uint num8 = source[9];
3875 uint num9 = source[10];
3876 uint num10 = source[11];
3877 if ((num7 | num8 | num9 | num10) > 127)
3878 {
3879 result.SetBadDateTimeFailure();
3880 return false;
3881 }
3882 int month;
3883 switch ((num7 << 24) | (num8 << 16) | (num9 << 8) | num10 | 0x20202000)
3884 {
3885 case 1784770080u:
3886 month = 1;
3887 break;
3888 case 1717920288u:
3889 month = 2;
3890 break;
3891 case 1835102752u:
3892 month = 3;
3893 break;
3894 case 1634759200u:
3895 month = 4;
3896 break;
3897 case 1835104544u:
3898 month = 5;
3899 break;
3900 case 1786080800u:
3901 month = 6;
3902 break;
3903 case 1786080288u:
3904 month = 7;
3905 break;
3906 case 1635084064u:
3907 month = 8;
3908 break;
3909 case 1936027680u:
3910 month = 9;
3911 break;
3912 case 1868788768u:
3913 month = 10;
3914 break;
3915 case 1852798496u:
3916 month = 11;
3917 break;
3918 case 1684366112u:
3919 month = 12;
3920 break;
3921 default:
3922 result.SetBadDateTimeFailure();
3923 return false;
3924 }
3925 uint num11 = (uint)(source[12] - 48);
3926 uint num12 = (uint)(source[13] - 48);
3927 uint num13 = (uint)(source[14] - 48);
3928 uint num14 = (uint)(source[15] - 48);
3929 if (num11 > 9 || num12 > 9 || num13 > 9 || num14 > 9)
3930 {
3931 result.SetBadDateTimeFailure();
3932 return false;
3933 }
3934 int year = (int)(num11 * 1000 + num12 * 100 + num13 * 10 + num14);
3935 if (source[16] != ' ')
3936 {
3937 result.SetBadDateTimeFailure();
3938 return false;
3939 }
3940 uint num15 = (uint)(source[17] - 48);
3941 uint num16 = (uint)(source[18] - 48);
3942 if (num15 > 9 || num16 > 9)
3943 {
3944 result.SetBadDateTimeFailure();
3945 return false;
3946 }
3947 int hour = (int)(num15 * 10 + num16);
3948 if (source[19] != ':')
3949 {
3950 result.SetBadDateTimeFailure();
3951 return false;
3952 }
3953 uint num17 = (uint)(source[20] - 48);
3954 uint num18 = (uint)(source[21] - 48);
3955 if (num17 > 9 || num18 > 9)
3956 {
3957 result.SetBadDateTimeFailure();
3958 return false;
3959 }
3960 int minute = (int)(num17 * 10 + num18);
3961 if (source[22] != ':')
3962 {
3963 result.SetBadDateTimeFailure();
3964 return false;
3965 }
3966 uint num19 = (uint)(source[23] - 48);
3967 uint num20 = (uint)(source[24] - 48);
3968 if (num19 > 9 || num20 > 9)
3969 {
3970 result.SetBadDateTimeFailure();
3971 return false;
3972 }
3973 int second = (int)(num19 * 10 + num20);
3974 if (source[25] != ' ' || source[26] != 'G' || source[27] != 'M' || source[28] != 'T')
3975 {
3976 result.SetBadDateTimeFailure();
3977 return false;
3978 }
3979 if (!parseInfo.calendar.TryToDateTime(year, month, day, hour, minute, second, 0, 0, out result.parsedDate))
3980 {
3981 result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar");
3982 return false;
3983 }
3984 if (dayOfWeek != result.parsedDate.DayOfWeek)
3985 {
3986 result.SetFailure(ParseFailureKind.FormatWithOriginalDateTime, "Format_BadDayOfWeek");
3987 return false;
3988 }
3989 return true;
3990 }
3991
3992 private static bool ParseFormatO(ReadOnlySpan<char> source, ref DateTimeResult result)
3993 {
3994 if ((uint)source.Length < 27u || source[4] != '-' || source[7] != '-' || source[10] != 'T' || source[13] != ':' || source[16] != ':' || source[19] != '.')
3995 {
3996 result.SetBadDateTimeFailure();
3997 return false;
3998 }
3999 uint num = (uint)(source[0] - 48);
4000 uint num2 = (uint)(source[1] - 48);
4001 uint num3 = (uint)(source[2] - 48);
4002 uint num4 = (uint)(source[3] - 48);
4003 if (num > 9 || num2 > 9 || num3 > 9 || num4 > 9)
4004 {
4005 result.SetBadDateTimeFailure();
4006 return false;
4007 }
4008 int year = (int)(num * 1000 + num2 * 100 + num3 * 10 + num4);
4009 uint num5 = (uint)(source[5] - 48);
4010 uint num6 = (uint)(source[6] - 48);
4011 if (num5 > 9 || num6 > 9)
4012 {
4013 result.SetBadDateTimeFailure();
4014 return false;
4015 }
4016 int month = (int)(num5 * 10 + num6);
4017 uint num7 = (uint)(source[8] - 48);
4018 uint num8 = (uint)(source[9] - 48);
4019 if (num7 > 9 || num8 > 9)
4020 {
4021 result.SetBadDateTimeFailure();
4022 return false;
4023 }
4024 int day = (int)(num7 * 10 + num8);
4025 uint num9 = (uint)(source[11] - 48);
4026 uint num10 = (uint)(source[12] - 48);
4027 if (num9 > 9 || num10 > 9)
4028 {
4029 result.SetBadDateTimeFailure();
4030 return false;
4031 }
4032 int hour = (int)(num9 * 10 + num10);
4033 uint num11 = (uint)(source[14] - 48);
4034 uint num12 = (uint)(source[15] - 48);
4035 if (num11 > 9 || num12 > 9)
4036 {
4037 result.SetBadDateTimeFailure();
4038 return false;
4039 }
4040 int minute = (int)(num11 * 10 + num12);
4041 uint num13 = (uint)(source[17] - 48);
4042 uint num14 = (uint)(source[18] - 48);
4043 if (num13 > 9 || num14 > 9)
4044 {
4045 result.SetBadDateTimeFailure();
4046 return false;
4047 }
4048 int second = (int)(num13 * 10 + num14);
4049 uint num15 = (uint)(source[20] - 48);
4050 uint num16 = (uint)(source[21] - 48);
4051 uint num17 = (uint)(source[22] - 48);
4052 uint num18 = (uint)(source[23] - 48);
4053 uint num19 = (uint)(source[24] - 48);
4054 uint num20 = (uint)(source[25] - 48);
4055 uint num21 = (uint)(source[26] - 48);
4056 if (num15 > 9 || num16 > 9 || num17 > 9 || num18 > 9 || num19 > 9 || num20 > 9 || num21 > 9)
4057 {
4058 result.SetBadDateTimeFailure();
4059 return false;
4060 }
4061 double num22 = (double)(num15 * 1000000 + num16 * 100000 + num17 * 10000 + num18 * 1000 + num19 * 100 + num20 * 10 + num21) / 10000000.0;
4062 if (!DateTime.TryCreate(year, month, day, hour, minute, second, 0, out var result2))
4063 {
4064 result.SetBadDateTimeFailure();
4065 return false;
4066 }
4067 if (!result2.TryAddTicks((long)Math.Round(num22 * 10000000.0), out result.parsedDate))
4068 {
4069 result.SetBadDateTimeFailure();
4070 return false;
4071 }
4072 if ((uint)source.Length > 27u)
4073 {
4074 char c = source[27];
4075 switch (c)
4076 {
4077 case 'Z':
4078 if (source.Length != 28)
4079 {
4080 result.SetBadDateTimeFailure();
4081 return false;
4082 }
4083 result.flags |= ParseFlags.TimeZoneUsed | ParseFlags.TimeZoneUtc;
4084 break;
4085 case '+':
4086 case '-':
4087 {
4088 int num25;
4089 int num26;
4090 if (source.Length == 33)
4091 {
4092 uint num23 = (uint)(source[28] - 48);
4093 uint num24 = (uint)(source[29] - 48);
4094 if (num23 > 9 || num24 > 9)
4095 {
4096 result.SetBadDateTimeFailure();
4097 return false;
4098 }
4099 num25 = (int)(num23 * 10 + num24);
4100 num26 = 30;
4101 }
4102 else
4103 {
4104 if (source.Length != 32)
4105 {
4106 result.SetBadDateTimeFailure();
4107 return false;
4108 }
4109 num25 = source[28] - 48;
4110 if ((uint)num25 > 9u)
4111 {
4112 result.SetBadDateTimeFailure();
4113 return false;
4114 }
4115 num26 = 29;
4116 }
4117 if (source[num26] != ':')
4118 {
4119 result.SetBadDateTimeFailure();
4120 return false;
4121 }
4122 uint num27 = (uint)(source[num26 + 1] - 48);
4123 uint num28 = (uint)(source[num26 + 2] - 48);
4124 if (num27 > 9 || num28 > 9)
4125 {
4126 result.SetBadDateTimeFailure();
4127 return false;
4128 }
4129 int minutes = (int)(num27 * 10 + num28);
4130 result.flags |= ParseFlags.TimeZoneUsed;
4131 result.timeZoneOffset = new TimeSpan(num25, minutes, 0);
4132 if (c == '-')
4133 {
4134 result.timeZoneOffset = result.timeZoneOffset.Negate();
4135 }
4136 break;
4137 }
4138 default:
4139 result.SetBadDateTimeFailure();
4140 return false;
4141 }
4142 }
4143 return DetermineTimeZoneAdjustments(ref result, DateTimeStyles.None, bTimeOnly: false);
4144 }
4145
4147 {
4148 return result.failure switch
4149 {
4150 ParseFailureKind.ArgumentNull => new ArgumentNullException(result.failureArgumentName, SR.GetResourceString(result.failureMessageID)),
4151 ParseFailureKind.Format => new FormatException(SR.GetResourceString(result.failureMessageID)),
4152 ParseFailureKind.FormatWithParameter => new FormatException(SR.Format(SR.GetResourceString(result.failureMessageID), result.failureMessageFormatArgument)),
4153 ParseFailureKind.FormatBadDateTimeCalendar => new FormatException(SR.Format(SR.GetResourceString(result.failureMessageID), new string(result.originalDateTimeString), result.calendar)),
4154 ParseFailureKind.FormatWithOriginalDateTime => new FormatException(SR.Format(SR.GetResourceString(result.failureMessageID), new string(result.originalDateTimeString))),
4155 ParseFailureKind.FormatWithFormatSpecifier => new FormatException(SR.Format(SR.GetResourceString(result.failureMessageID), new string(result.failedFormatSpecifier))),
4156 ParseFailureKind.FormatWithOriginalDateTimeAndParameter => new FormatException(SR.Format(SR.GetResourceString(result.failureMessageID), new string(result.originalDateTimeString), result.failureMessageFormatArgument)),
4157 _ => null,
4158 };
4159 }
4160}
static string GetRealFormat(ReadOnlySpan< char > format, DateTimeFormatInfo dtfi)
static bool AdjustTimeZoneToUniversal(ref DateTimeResult result)
static bool TryParseExactMultiple(ReadOnlySpan< char > s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, ref DateTimeResult result)
static bool ParseJapaneseEraStart(ref __DTString str, DateTimeFormatInfo dtfi)
static bool TryParse(ReadOnlySpan< char > s, DateTimeFormatInfo dtfi, DateTimeStyles styles, out DateTime result, out TimeSpan offset)
static readonly DS[][] s_dateParsingStates
static Exception GetDateTimeParseException(ref DateTimeResult result)
static bool SetDateYMD(ref DateTimeResult result, int year, int month, int day)
static bool GetDayOfNNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static bool ParseFractionExact(ref __DTString str, int maxDigitLen, ref double result)
static bool MatchEraName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
static bool TryParseExact(ReadOnlySpan< char > s, ReadOnlySpan< char > format, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result, out TimeSpan offset)
static bool DetermineTimeZoneAdjustments(ref DateTimeResult result, DateTimeStyles styles, bool bTimeOnly)
static bool GetYearMonthDayOrder(string datePattern, out int order)
static string ExpandPredefinedFormat(ReadOnlySpan< char > format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
static bool GetDayOfMNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static bool GetTimeZoneName(ref __DTString str)
static bool ParseDigits(ref __DTString str, int digitLen, out int result)
static readonly MatchNumberDelegate s_hebrewNumberParser
static bool ParseTimeZoneOffset(ref __DTString str, int len, ref TimeSpan result)
static bool TryParseExactMultiple(ReadOnlySpan< char > s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result, out TimeSpan offset)
static bool CheckDefaultDateTime(ref DateTimeResult result, ref Calendar cal, DateTimeStyles styles)
static bool GetMonthDayOrder(string pattern, out int order)
static unsafe bool TryParse(ReadOnlySpan< char > s, DateTimeFormatInfo dtfi, DateTimeStyles styles, ref DateTimeResult result)
static bool GetDayOfYM(ref DateTimeResult result, ref DateTimeRawInfo raw)
static bool GetDayOfNM(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static bool TryAdjustYear(ref DateTimeResult result, int year, out int adjustedYear)
static void AdjustTimeMark(DateTimeFormatInfo dtfi, ref DateTimeRawInfo raw)
static bool GetTimeOfNNN(ref DateTimeResult result, ref DateTimeRawInfo raw)
static bool TryParseExactMultiple(ReadOnlySpan< char > s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result)
static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref DateTimeRawInfo raw, ref DateTimeResult result, ref DateTimeFormatInfo dtfi, DateTimeStyles styles)
static bool ProcessDateTimeSuffix(ref DateTimeResult result, ref DateTimeRawInfo raw, ref DateTimeToken dtok)
static bool IsDigit(char ch)
static bool GetDayOfYN(ref DateTimeResult result, ref DateTimeRawInfo raw)
static bool CheckNewValue(ref int currentValue, int newValue, char patternChar, ref DateTimeResult result)
static bool MatchAbbreviatedTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result)
static DateTime Parse(ReadOnlySpan< char > s, DateTimeFormatInfo dtfi, DateTimeStyles styles, out TimeSpan offset)
static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result)
static DateTime ParseExactMultiple(ReadOnlySpan< char > s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, out TimeSpan offset)
static DateTime ParseExact(ReadOnlySpan< char > s, ReadOnlySpan< char > format, DateTimeFormatInfo dtfi, DateTimeStyles style)
static bool ParseDigits(ref __DTString str, int minDigitLen, int maxDigitLen, out int result)
static bool GetDateOfNNDS(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static bool TryParseQuoteString(ReadOnlySpan< char > format, int pos, StringBuilder result, out int returnValue)
static bool SetDateDMY(ref DateTimeResult result, int day, int month, int year)
static bool DateTimeOffsetTimeZonePostProcessing(ref DateTimeResult result, DateTimeStyles styles)
static bool VerifyValidPunctuation(ref __DTString str)
static void ConfigureFormatR(ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
static bool DoStrictParse(ReadOnlySpan< char > s, ReadOnlySpan< char > formatParam, DateTimeStyles styles, DateTimeFormatInfo dtfi, ref DateTimeResult result)
static bool AdjustTimeZoneToLocal(ref DateTimeResult result, bool bTimeOnly)
static bool HandleTimeZone(ref __DTString str, ref DateTimeResult result)
static bool GetHebrewDayOfNM(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static bool GetTimeOfNN(ref DateTimeResult result, ref DateTimeRawInfo raw)
static bool TryParseExact(ReadOnlySpan< char > s, ReadOnlySpan< char > format, DateTimeFormatInfo dtfi, DateTimeStyles style, ref DateTimeResult result)
static bool ProcessTerminalState(DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static bool GetYearMonthOrder(string pattern, out int order)
static DateTime ParseExact(ReadOnlySpan< char > s, ReadOnlySpan< char > format, DateTimeFormatInfo dtfi, DateTimeStyles style, out TimeSpan offset)
static bool GetDateOfNDS(ref DateTimeResult result, ref DateTimeRawInfo raw)
static bool TryParse(ReadOnlySpan< char > s, DateTimeFormatInfo dtfi, DateTimeStyles styles, out DateTime result)
static bool GetDayOfYNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static DateTime GetDateTimeNow(ref DateTimeResult result, ref DateTimeStyles styles)
static DateTime Parse(ReadOnlySpan< char > s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
static void GetDefaultYear(ref DateTimeResult result, ref DateTimeStyles styles)
static bool GetTimeOfN(ref DateTimeResult result, ref DateTimeRawInfo raw)
static bool ParseByFormat(ref __DTString str, ref __DTString format, ref ParsingInfo parseInfo, DateTimeFormatInfo dtfi, ref DateTimeResult result)
delegate bool MatchNumberDelegate(ref __DTString str, int digitLen, out int result)
static DateTime ParseExactMultiple(ReadOnlySpan< char > s, string[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style)
static bool MatchMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
static bool GetDayOfNNY(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static bool SetDateYDM(ref DateTimeResult result, int year, int day, int month)
static bool GetDayOfMN(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static bool GetDayOfNN(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static bool ProcessHebrewTerminalState(DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
static bool TryParseExact(ReadOnlySpan< char > s, ReadOnlySpan< char > format, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result)
static bool MatchHebrewDigits(ref __DTString str, int digitLen, out int number)
static bool MatchAbbreviatedDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
static void ConfigureFormatOS(ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo)
static bool MatchWord(ref __DTString str, string target)
static bool ParseFormatO(ReadOnlySpan< char > source, ref DateTimeResult result)
static bool MatchAbbreviatedMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
static bool ParseFraction(ref __DTString str, out double result)
static bool SetDateMDY(ref DateTimeResult result, int month, int day, int year)
static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
static bool ParseFormatR(ReadOnlySpan< char > source, ref ParsingInfo parseInfo, ref DateTimeResult result)
static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, ref DateTimeResult result)
static bool ParseTimeZone(ref __DTString str, ref TimeSpan result)
static bool GetDayOfYMN(ref DateTimeResult result, ref DateTimeRawInfo raw)
static bool GetDateOfDSN(ref DateTimeResult result, ref DateTimeRawInfo raw)
static bool AdjustHour(ref int hour, TM timeMark)
static bool ParseSign(ref __DTString str, ref bool result)
virtual int ToFourDigitYear(int year)
Definition Calendar.cs:352
DayOfWeek GetDayOfWeek(DateTime time)
virtual CalendarId ID
Definition Calendar.cs:19
virtual bool TryToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era, out DateTime result)
Definition Calendar.cs:311
static HebrewNumberParsingState ParseByChar(char ch, ref HebrewNumberParsingContext context)
static decimal Round(decimal d)
Definition Math.cs:1096
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string GetResourceString(string resourceKey)
Definition SR.cs:101
Definition SR.cs:7
static string GetStringAndRelease(StringBuilder sb)
static void Release(StringBuilder sb)
static StringBuilder Acquire(int capacity=16)
StringBuilder Append(char value, int repeatCount)
static TimeZoneInfo Local
TimeSpan GetUtcOffset(DateTimeOffset dateTimeOffset)
static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone)
static TimeSpan GetLocalUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
DayOfWeek
Definition DayOfWeek.cs:4
TokenType
Definition TokenType.cs:4
DTSubStringType type
unsafe void Init(int *numberBuffer)
DateTimeParse.TM timeMark
void Init(ReadOnlySpan< char > originalDateTimeString)
DateTimeParse.DTT dtt
static readonly DateTime MinValue
Definition DateTime.cs:35
static DateTime Now
Definition DateTime.cs:103
static unsafe DateTime UtcNow
Definition DateTime.cs:142
static DateTime SpecifyKind(DateTime value, DateTimeKind kind)
Definition DateTime.cs:756
static bool TryCreate(int year, int month, int day, int hour, int minute, int second, int millisecond, out DateTime result)
Definition DateTime.cs:1365
DateTimeParse.TM timeMark
static readonly TimeSpan Zero
Definition TimeSpan.cs:21