Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ DoStrictParse()

static bool System.DateTimeParse.DoStrictParse ( ReadOnlySpan< char > s,
ReadOnlySpan< char > formatParam,
DateTimeStyles styles,
DateTimeFormatInfo dtfi,
ref DateTimeResult result )
inlinestaticprivate

Definition at line 3670 of file DateTimeParse.cs.

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 }
3749 catch (ArgumentOutOfRangeException)
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 }
static bool DetermineTimeZoneAdjustments(ref DateTimeResult result, DateTimeStyles styles, bool bTimeOnly)
static string ExpandPredefinedFormat(ReadOnlySpan< char > format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
static readonly MatchNumberDelegate s_hebrewNumberParser
static bool CheckDefaultDateTime(ref DateTimeResult result, ref Calendar cal, DateTimeStyles styles)
static void ConfigureFormatR(ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
static bool ParseByFormat(ref __DTString str, ref __DTString format, ref ParsingInfo parseInfo, DateTimeFormatInfo dtfi, ref DateTimeResult result)
static void ConfigureFormatOS(ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo)
static bool ParseFormatO(ReadOnlySpan< char > source, ref DateTimeResult result)
static bool ParseFormatR(ReadOnlySpan< char > source, ref ParsingInfo parseInfo, ref DateTimeResult result)

References System.Globalization.DateTimeFormatInfo.Calendar, System.ParsingInfo.calendar, System.DateTimeParse.CheckDefaultDateTime(), System.DateTimeParse.ConfigureFormatOS(), System.DateTimeParse.ConfigureFormatR(), System.ParsingInfo.dayOfWeek, System.DateTimeParse.DetermineTimeZoneAdjustments(), System.DateTimeParse.ExpandPredefinedFormat(), System.ParsingInfo.fAllowInnerWhite, System.ParsingInfo.fAllowTrailingWhite, System.format, System.ParsingInfo.fUseHour12, System.ParsingInfo.fUseTwoDigitYear, System.Globalization.Calendar.GetDayOfWeek(), System.Globalization.Calendar.ID, System.ParsingInfo.Init(), System.ReadOnlySpan< T >.Length, System.DateTimeParse.ParseByFormat(), System.DateTimeParse.ParseFormatO(), System.DateTimeParse.ParseFormatR(), System.Math.Round(), System.s, System.DateTimeParse.s_hebrewNumberParser, System.str, System.ParsingInfo.timeMark, System.Globalization.Calendar.ToFourDigitYear(), System.__DTString.TrimTail(), and System.Globalization.Calendar.TryToDateTime().

Referenced by System.DateTimeParse.TryParseExact().