GetNumber() private method

private GetNumber ( int index ) : int
index int
return int
示例#1
0
 private static bool GetDayOfYNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
 {
     int num3;
     if ((result.flags & ParseFlags.HaveDate) != 0)
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
         return false;
     }
     int number = raw.GetNumber(0);
     int month = raw.GetNumber(1);
     string shortDatePattern = dtfi.ShortDatePattern;
     if (dtfi.CultureId == 0x437)
     {
         shortDatePattern = dtfi.LongDatePattern;
     }
     if (GetYearMonthDayOrder(shortDatePattern, dtfi, out num3) && (num3 == 3))
     {
         if (SetDateYMD(ref result, raw.year, month, number))
         {
             result.flags |= ParseFlags.HaveDate;
             return true;
         }
     }
     else if (SetDateYMD(ref result, raw.year, number, month))
     {
         result.flags |= ParseFlags.HaveDate;
         return true;
     }
     result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
     return false;
 }
		private static bool GetDateOfNDS(ref DateTimeResult result, ref DateTimeRawInfo raw)
		{
			if (result.Month == -1)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			if (result.Year != -1)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			result.Year = DateTimeParse.AdjustYear(ref result, raw.GetNumber(0));
			result.Day = 1;
			return true;
		}
		internal static bool ProcessHebrewTerminalState(DateTimeParse.DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
		{
			switch (dps)
			{
				case DateTimeParse.DS.DX_MN:
				case DateTimeParse.DS.DX_NM:
				{
					DateTimeParse.GetDefaultYear(ref result, ref styles);
					if (!dtfi.YearMonthAdjustment(ref result.Year, ref raw.month, true))
					{
						result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
						return false;
					}
					if (!DateTimeParse.GetHebrewDayOfNM(ref result, ref raw, dtfi))
					{
						return false;
					}
					goto IL_160;
				}
				case DateTimeParse.DS.DX_MNN:
				{
					raw.year = raw.GetNumber(1);
					if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true))
					{
						result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
						return false;
					}
					if (!DateTimeParse.GetDayOfMNN(ref result, ref raw, dtfi))
					{
						return false;
					}
					goto IL_160;
				}
				case DateTimeParse.DS.DX_YMN:
				{
					if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true))
					{
						result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
						return false;
					}
					if (!DateTimeParse.GetDayOfYMN(ref result, ref raw, dtfi))
					{
						return false;
					}
					goto IL_160;
				}
				case DateTimeParse.DS.DX_YM:
				{
					if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true))
					{
						result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
						return false;
					}
					if (!DateTimeParse.GetDayOfYM(ref result, ref raw, dtfi))
					{
						return false;
					}
					goto IL_160;
				}
				case DateTimeParse.DS.TX_N:
				{
					if (!DateTimeParse.GetTimeOfN(dtfi, ref result, ref raw))
					{
						return false;
					}
					goto IL_160;
				}
				case DateTimeParse.DS.TX_NN:
				{
					if (!DateTimeParse.GetTimeOfNN(dtfi, ref result, ref raw))
					{
						return false;
					}
					goto IL_160;
				}
				case DateTimeParse.DS.TX_NNN:
				{
					if (!DateTimeParse.GetTimeOfNNN(dtfi, ref result, ref raw))
					{
						return false;
					}
					goto IL_160;
				}
			}
			result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
			return false;
			IL_160:
			if (dps > DateTimeParse.DS.ERROR)
			{
				raw.numCount = 0;
			}
			return true;
		}
		private static bool GetDayOfYN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
		{
			if ((result.flags & ParseFlags.HaveDate) != (ParseFlags)0)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			if (DateTimeParse.SetDateYMD(ref result, raw.year, raw.GetNumber(0), 1))
			{
				result.flags |= ParseFlags.HaveDate;
				return true;
			}
			result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
			return false;
		}
		private static bool GetTimeOfNNN(DateTimeFormatInfo dtfi, ref DateTimeResult result, ref DateTimeRawInfo raw)
		{
			if ((result.flags & ParseFlags.HaveTime) != (ParseFlags)0)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			result.Hour = raw.GetNumber(0);
			result.Minute = raw.GetNumber(1);
			result.Second = raw.GetNumber(2);
			result.flags |= ParseFlags.HaveTime;
			return true;
		}
		private static bool GetHebrewDayOfNM(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
		{
			int num;
			if (!DateTimeParse.GetMonthDayOrder(dtfi.MonthDayPattern, dtfi, out num))
			{
				result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.MonthDayPattern);
				return false;
			}
			result.Month = raw.month;
			if ((num == 7 || num == 6) && result.calendar.IsValidDay(result.Year, result.Month, raw.GetNumber(0), result.era))
			{
				result.Day = raw.GetNumber(0);
				return true;
			}
			result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
			return false;
		}
		private static bool GetDayOfMNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
		{
			if ((result.flags & ParseFlags.HaveDate) != (ParseFlags)0)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			int number = raw.GetNumber(0);
			int number2 = raw.GetNumber(1);
			int num;
			if (!DateTimeParse.GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out num))
			{
				result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
				return false;
			}
			if (num == 1)
			{
				int year;
				if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number2), raw.month, number, result.era))
				{
					result.SetDate(year, raw.month, number);
					result.flags |= ParseFlags.HaveDate;
					return true;
				}
				if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number), raw.month, number2, result.era))
				{
					result.SetDate(year, raw.month, number2);
					result.flags |= ParseFlags.HaveDate;
					return true;
				}
			}
			else
			{
				if (num == 0)
				{
					int year;
					if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number), raw.month, number2, result.era))
					{
						result.SetDate(year, raw.month, number2);
						result.flags |= ParseFlags.HaveDate;
						return true;
					}
					if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number2), raw.month, number, result.era))
					{
						result.SetDate(year, raw.month, number);
						result.flags |= ParseFlags.HaveDate;
						return true;
					}
				}
				else
				{
					if (num == 2)
					{
						int year;
						if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number2), raw.month, number, result.era))
						{
							result.SetDate(year, raw.month, number);
							result.flags |= ParseFlags.HaveDate;
							return true;
						}
						if (result.calendar.IsValidDay(year = DateTimeParse.AdjustYear(ref result, number), raw.month, number2, result.era))
						{
							result.SetDate(year, raw.month, number2);
							result.flags |= ParseFlags.HaveDate;
							return true;
						}
					}
				}
			}
			result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
			return false;
		}
示例#8
0
        private static Boolean GetDayOfNM(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
        {
            if ((result.flags & ParseFlags.HaveDate) != 0) {
                // Multiple dates in the input string
                result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                return false;
            }

            // The interpretation is based on the MonthDayPattern and YearMonthPattern
            //
            //    MonthDayPattern   YearMonthPattern  Interpretation
            //    ---------------   ----------------  ---------------
            //    MMMM dd           MMMM yyyy         Day
            //    MMMM dd           yyyy MMMM         Year
            //    dd MMMM           MMMM yyyy         Day
            //    dd MMMM           yyyy MMMM         Day
            //
            // In the first and last cases, it could be either or neither, but a day is a better default interpretation
            // than a 2 digit year.

            int monthDayOrder;
            if (!GetMonthDayOrder(dtfi.MonthDayPattern, dtfi, out monthDayOrder)) {
                result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.MonthDayPattern);
                return false;
            }
            if (monthDayOrder == ORDER_MD) {
                int yearMonthOrder;
                if (!GetYearMonthOrder(dtfi.YearMonthPattern, dtfi, out yearMonthOrder)) {
                    result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.YearMonthPattern);
                    return false;
                }
                if (yearMonthOrder == ORDER_YM) {
                    int year;
                    if (!TryAdjustYear(ref result, raw.GetNumber(0), out year) || !SetDateYMD(ref result, year, raw.month, 1)) {
                        result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                        return false;
                    }
                    return true;
                }
            }

            GetDefaultYear(ref result, ref styles);
            if (!SetDateYMD(ref result, result.Year, raw.month, raw.GetNumber(0))) {
                result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                return false;
            }
            return true;
        }
示例#9
0
        private static Boolean GetDayOfMNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
        {
            if ((result.flags & ParseFlags.HaveDate) != 0) {
                // Multiple dates in the input string
                result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                return false;
            }

            int n1 = raw.GetNumber(0);
            int n2 = raw.GetNumber(1);

            int order;
            if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out order)) {
                result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
                return false;
            }
            int year;

            if (order == ORDER_MDY)
            {
                if (TryAdjustYear(ref result, n2, out year) && result.calendar.IsValidDay(year, raw.month, n1, result.era))
                {
                    result.SetDate(year, raw.month, n1);      // MDY
                    result.flags |= ParseFlags.HaveDate;
                    return true;
                }
                else if (TryAdjustYear(ref result, n1, out year) && result.calendar.IsValidDay(year, raw.month, n2, result.era))
                {
                    result.SetDate(year, raw.month, n2);      // YMD
                    result.flags |= ParseFlags.HaveDate;
                    return true;
                }
            }
            else if (order == ORDER_YMD)
            {
                if (TryAdjustYear(ref result, n1, out year) && result.calendar.IsValidDay(year, raw.month, n2, result.era))
                {
                    result.SetDate(year, raw.month, n2);      // YMD
                    result.flags |= ParseFlags.HaveDate;
                    return true;
                }
                else if (TryAdjustYear(ref result, n2, out year) && result.calendar.IsValidDay(year, raw.month, n1, result.era))
                {
                    result.SetDate(year, raw.month, n1);      // DMY
                    result.flags |= ParseFlags.HaveDate;
                    return true;
                }
            }
            else if (order == ORDER_DMY)
            {
                if (TryAdjustYear(ref result, n2, out year) && result.calendar.IsValidDay(year, raw.month, n1, result.era))
                {
                    result.SetDate(year, raw.month, n1);      // DMY
                    result.flags |= ParseFlags.HaveDate;
                    return true;
                }
                else if (TryAdjustYear(ref result, n1, out year) && result.calendar.IsValidDay(year, raw.month, n2, result.era))
                {
                    result.SetDate(year, raw.month, n2);      // YMD
                    result.flags |= ParseFlags.HaveDate;
                    return true;
                }
            }

            result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
            return false;
        }
示例#10
0
        // Processing teriminal case: DS.DX_NNN
        private static Boolean GetDayOfNNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
        {
            if ((result.flags & ParseFlags.HaveDate) != 0) {
                // Multiple dates in the input string
                result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                return false;
            }

            int n1 = raw.GetNumber(0);
            int n2 = raw.GetNumber(1);;
            int n3 = raw.GetNumber(2);

            int order;
            if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out order)) {
                result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
                return false;
            }
            int year;

            if (order == ORDER_YMD) {
                if (TryAdjustYear(ref result, n1, out year) && SetDateYMD(ref result, year, n2, n3))         // YMD
                {
                    result.flags |= ParseFlags.HaveDate;
                    return true;
                }
            } else if (order == ORDER_MDY) {
                if (TryAdjustYear(ref result, n3, out year) && SetDateMDY(ref result, n1, n2, year))         // MDY
                {
                    result.flags |= ParseFlags.HaveDate;
                    return true;
                }
            } else if (order == ORDER_DMY) {
                if (TryAdjustYear(ref result, n3, out year) && SetDateDMY(ref result, n1, n2, year))         // DMY
                {
                    result.flags |= ParseFlags.HaveDate;
                    return true;
                }
            } else if (order == ORDER_YDM) {
                if (TryAdjustYear(ref result, n1, out year) && SetDateYDM(ref result, year, n2, n3))         // YDM
                {
                    result.flags |= ParseFlags.HaveDate;
                    return true;
                }
            }
            result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
            return false;
        }
示例#11
0
        ////////////////////////////////////////////////////////////////////////
        //  Actions:
        //  Deal with the terminal state for Hebrew Month/Day pattern
        //
        ////////////////////////////////////////////////////////////////////////

        private static Boolean GetHebrewDayOfNM(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
        {
            int monthDayOrder;
            if (!GetMonthDayOrder(dtfi.MonthDayPattern, dtfi, out monthDayOrder)) {
                result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.MonthDayPattern);
                return false;
            }
            result.Month = raw.month;
            if (monthDayOrder == ORDER_DM || monthDayOrder == ORDER_MD)
            {
                if (result.calendar.IsValidDay(result.Year, result.Month, raw.GetNumber(0), result.era))
                {
                    result.Day  = raw.GetNumber(0);
                    return true;
                }
            }
            result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
            return false;
        }
 private static Boolean GetDateOfNDS(ref DateTimeResult result, ref DateTimeRawInfo raw)
 {
     if (result.Month == -1)
     {
         //Should have a month suffix
         result.SetFailure(ParseFailureKind.Format, SR.Format_BadDateTime, null);
         return false;
     }
     if (result.Year != -1)
     {
         // Aleady has a year suffix
         result.SetFailure(ParseFailureKind.Format, SR.Format_BadDateTime, null);
         return false;
     }
     result.Year = AdjustYear(ref result, raw.GetNumber(0));
     result.Day = 1;
     return true;
 }
            private static Boolean GetTimeOfNN(DateTimeFormatInfo dtfi, ref DateTimeResult result, ref DateTimeRawInfo raw)
            {
                if ((result.flags & ParseFlags.HaveTime) != 0)
                {
                    // Multiple times in the input string
                    result.SetFailure(ParseFailureKind.Format, SR.Format_BadDateTime, null);
                    return false;
                }

                result.Hour = raw.GetNumber(0);
                result.Minute = raw.GetNumber(1);
                result.flags |= ParseFlags.HaveTime;
                return true;
            }
            // Processing teriminal case: DS.DX_NN
            private static Boolean GetDayOfNN(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
            {
                if ((result.flags & ParseFlags.HaveDate) != 0)
                {
                    // Multiple dates in the input string
                    result.SetFailure(ParseFailureKind.Format, SR.Format_BadDateTime, null);
                    return false;
                }

                int n1 = raw.GetNumber(0);
                int n2 = raw.GetNumber(1);

                GetDefaultYear(ref result, ref styles);

                int order;
                if (!GetMonthDayOrder(dtfi.MonthDayPattern, dtfi, out order))
                {
                    result.SetFailure(ParseFailureKind.FormatWithParameter, SR.Format_BadDatePattern, dtfi.MonthDayPattern);
                    return false;
                }

                if (order == ORDER_MD)
                {
                    if (SetDateYMD(ref result, result.Year, n1, n2))                           // MD
                    {
                        result.flags |= ParseFlags.HaveDate;
                        return true;
                    }
                }
                else
                {
                    // ORDER_DM
                    if (SetDateYMD(ref result, result.Year, n2, n1))                           // DM
                    {
                        result.flags |= ParseFlags.HaveDate;
                        return true;
                    }
                }
                result.SetFailure(ParseFailureKind.Format, SR.Format_BadDateTime, null);
                return false;
            }
示例#15
0
        ////////////////////////////////////////////////////////////////////////
        //
        // Actions:
        // This is used by DateTime.Parse().
        // Process the terminal state for the Hebrew calendar parsing.
        //
        ////////////////////////////////////////////////////////////////////////

        internal static Boolean ProcessHebrewTerminalState(DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) {
            // The following are accepted terminal state for Hebrew date.
            switch (dps) {
                case DS.DX_MNN:
                    // Deal with the default long/short date format when the year number is ambigous (i.e. year < 100).
                    raw.year = raw.GetNumber(1);
                    if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true)) {
                        result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
                        return false;
                    }
                    if (!GetDayOfMNN(ref result, ref raw, dtfi)) {
                        return false;
                    }
                    break;
                case DS.DX_YMN:
                    // Deal with the default long/short date format when the year number is NOT ambigous (i.e. year >= 100).
                    if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true)) {
                        result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
                        return false;
                    }
                    if (!GetDayOfYMN(ref result, ref raw, dtfi)) {
                        return false;
                    }
                    break;
                case DS.DX_NM:
                case DS.DX_MN:
                    // Deal with Month/Day pattern.
                    GetDefaultYear(ref result, ref styles);
                    if (!dtfi.YearMonthAdjustment(ref result.Year, ref raw.month, true)) {
                        result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
                        return false;
                    }
                    if (!GetHebrewDayOfNM(ref result, ref raw, dtfi)) {
                        return false;
                    }
                    break;
                case DS.DX_YM:
                    // Deal with Year/Month pattern.
                    if (!dtfi.YearMonthAdjustment(ref raw.year, ref raw.month, true)) {
                        result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
                        return false;
                    }
                    if (!GetDayOfYM(ref result, ref raw, dtfi)) {
                        return false;
                    }
                    break;
                case DS.TX_N:
                    // Deal hour + AM/PM
                    if (!GetTimeOfN(dtfi, ref result, ref raw)) {
                        return false;
                    }
                    break;
                case DS.TX_NN:
                    if (!GetTimeOfNN(dtfi, ref result, ref raw)) {
                        return false;
                    }
                    break;
                case DS.TX_NNN:
                    if (!GetTimeOfNNN(dtfi, ref result, ref raw)) {
                        return false;
                    }
                    break;
                default:
                    result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                    return false;

            }
            if (dps > DS.ERROR)
            {
                //
                // We have reached a terminal state. Reset the raw num count.
                //
                raw.numCount = 0;
            }
            return true;
        }
示例#16
0
        private static Boolean GetDayOfYNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) {

            if ((result.flags & ParseFlags.HaveDate) != 0) {
                // Multiple dates in the input string
                result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                return false;
            }

            int n1 = raw.GetNumber(0);
            int n2 = raw.GetNumber(1);
            String pattern = dtfi.ShortDatePattern;

            // For compatibility, don't throw if we can't determine the order, but default to YMD instead
            int order;
            if (GetYearMonthDayOrder(pattern, dtfi, out order) && order == ORDER_YDM) {
                if (SetDateYMD(ref result, raw.year, n2, n1)) {
                    result.flags |= ParseFlags.HaveDate;
                    return true; // Year + DM
                }
            }
            else {
                if (SetDateYMD(ref result, raw.year, n1, n2)) {
                    result.flags |= ParseFlags.HaveDate;
                    return true; // Year + MD
                }
            }
            result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
            return false;
        }
示例#17
0
        //
        // Parse the ISO8601 format string found during Parse();
        //
        //
        private static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, ref DateTimeResult result) {
            if (raw.year < 0 || raw.GetNumber(0) < 0 || raw.GetNumber(1) < 0) {
            }
            str.Index--;
            int hour, minute;
            int second = 0;
            double partSecond = 0;

            str.SkipWhiteSpaces();
            if (!ParseDigits(ref str, 2, out hour)) {
                result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                return false;
            }
            str.SkipWhiteSpaces();
            if (!str.Match(':')) {
                result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                return false;
            }
            str.SkipWhiteSpaces();
            if (!ParseDigits(ref str, 2, out minute)) {
                result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                return false;
            }
            str.SkipWhiteSpaces();
            if (str.Match(':')) {
                str.SkipWhiteSpaces();
                if (!ParseDigits(ref str, 2, out second)) {
                    result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                    return false;
                }
                if (str.Match('.')) {
                    if (!ParseFraction(ref str, out partSecond)) {
                        result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                        return false;
                    }
                    str.Index--;
                }
                str.SkipWhiteSpaces();
            }
            if (str.GetNext()) {
                char ch = str.GetChar();
                if (ch == '+' || ch == '-') {
                    result.flags |= ParseFlags.TimeZoneUsed;
                    if (!ParseTimeZone(ref str, ref result.timeZoneOffset)) {
                        result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                        return false;
                    }
                } else if (ch == 'Z' || ch == 'z') {
                    result.flags |= ParseFlags.TimeZoneUsed;
                    result.timeZoneOffset = TimeSpan.Zero;
                    result.flags |= ParseFlags.TimeZoneUtc;
                } else {
                    str.Index--;
                }
                str.SkipWhiteSpaces();
                if (str.Match('#')) {
                    if (!VerifyValidPunctuation(ref str)) {
                        result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                        return false;                        
                    }
                    str.SkipWhiteSpaces();
                }
                if (str.Match('\0')) {
                    if (!VerifyValidPunctuation(ref str)) {
                        result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                        return false;                        
                    }
                }
                if (str.GetNext()) {                
                    // If this is true, there were non-white space characters remaining in the DateTime
                    result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                    return false;
                }
            }

            DateTime time;
            Calendar calendar = GregorianCalendar.GetDefaultInstance();
            if (!calendar.TryToDateTime(raw.year, raw.GetNumber(0), raw.GetNumber(1),
                    hour, minute, second, 0, result.era, out time)) {
                result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
                return false;
            }
            
            time = time.AddTicks((long)Math.Round(partSecond * Calendar.TicksPerSecond));
            result.parsedDate = time;
            if (!DetermineTimeZoneAdjustments(ref result, styles, false)) {
                return false;
            }
            return true;
        }
示例#18
0
        private static Boolean GetDayOfNNY(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) {

            if ((result.flags & ParseFlags.HaveDate) != 0) {
                // Multiple dates in the input string
                result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                return false;
            }

            int n1 = raw.GetNumber(0);
            int n2 = raw.GetNumber(1);

            int order;
            if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out order)) {
                result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
                return false;
            }

            if (order == ORDER_MDY || order == ORDER_YMD) {
                if (SetDateYMD(ref result, raw.year, n1, n2)) {
                    result.flags |= ParseFlags.HaveDate;
                    return true; // MD + Year
                }
            } else {
                if (SetDateYMD(ref result, raw.year, n2, n1)) {
                    result.flags |= ParseFlags.HaveDate;
                    return true; // DM + Year
                }
            }
            result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
            return false;
        }
		private static bool GetDayOfNM(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
		{
			if ((result.flags & ParseFlags.HaveDate) != (ParseFlags)0)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			int num;
			if (!DateTimeParse.GetMonthDayOrder(dtfi.MonthDayPattern, dtfi, out num))
			{
				result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.MonthDayPattern);
				return false;
			}
			if (num == 6)
			{
				int num2;
				if (!DateTimeParse.GetYearMonthOrder(dtfi.YearMonthPattern, dtfi, out num2))
				{
					result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.YearMonthPattern);
					return false;
				}
				if (num2 == 4)
				{
					if (!DateTimeParse.SetDateYMD(ref result, DateTimeParse.AdjustYear(ref result, raw.GetNumber(0)), raw.month, 1))
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					return true;
				}
			}
			DateTimeParse.GetDefaultYear(ref result, ref styles);
			if (!DateTimeParse.SetDateYMD(ref result, result.Year, raw.month, raw.GetNumber(0)))
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			return true;
		}
示例#20
0
        private static Boolean GetDayOfYN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
        {
            if ((result.flags & ParseFlags.HaveDate) != 0) {
                // Multiple dates in the input string
                result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                return false;
            }

            if (SetDateYMD(ref result, raw.year, raw.GetNumber(0), 1))
            {
                result.flags |= ParseFlags.HaveDate;
                return true;
            }
            result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
            return false;
        }
		private static bool GetDayOfNNY(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
		{
			if ((result.flags & ParseFlags.HaveDate) != (ParseFlags)0)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			int number = raw.GetNumber(0);
			int number2 = raw.GetNumber(1);
			int num;
			if (!DateTimeParse.GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out num))
			{
				result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
				return false;
			}
			if (num == 1 || num == 0)
			{
				if (DateTimeParse.SetDateYMD(ref result, raw.year, number, number2))
				{
					result.flags |= ParseFlags.HaveDate;
					return true;
				}
			}
			else
			{
				if (DateTimeParse.SetDateYMD(ref result, raw.year, number2, number))
				{
					result.flags |= ParseFlags.HaveDate;
					return true;
				}
			}
			result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
			return false;
		}
示例#22
0
 private static Boolean GetTimeOfN(DateTimeFormatInfo dtfi, ref DateTimeResult result, ref DateTimeRawInfo raw)
 {
     if ((result.flags & ParseFlags.HaveTime) != 0) {
         // Multiple times in the input string
         result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
         return false;
     }
     //
     // In this case, we need a time mark. Check if so.
     //
     if (raw.timeMark == TM.NotSet)
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
         return false;
     }
     result.Hour = raw.GetNumber(0);
     result.flags |= ParseFlags.HaveTime;
     return true;
 }
		private static bool GetTimeOfN(DateTimeFormatInfo dtfi, ref DateTimeResult result, ref DateTimeRawInfo raw)
		{
			if ((result.flags & ParseFlags.HaveTime) != (ParseFlags)0)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			if (raw.timeMark == DateTimeParse.TM.NotSet)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			result.Hour = raw.GetNumber(0);
			result.flags |= ParseFlags.HaveTime;
			return true;
		}
示例#24
0
 private static Boolean GetTimeOfNNN(DateTimeFormatInfo dtfi, ref DateTimeResult result, ref DateTimeRawInfo raw)
 {
     if ((result.flags & ParseFlags.HaveTime) != 0) {
         // Multiple times in the input string
         result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
         return false;
     }
     Contract.Assert(raw.numCount >= 3, "raw.numCount >= 3");
     result.Hour = raw.GetNumber(0);
     result.Minute   = raw.GetNumber(1);
     result.Second   = raw.GetNumber(2);
     result.flags |= ParseFlags.HaveTime;
     return true;
 }
		private static bool GetDateOfDSN(ref DateTimeResult result, ref DateTimeRawInfo raw)
		{
			if (raw.numCount != 1 || result.Day != -1)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			result.Day = raw.GetNumber(0);
			return true;
		}
示例#26
0
 private static Boolean GetDateOfNDS(ref DateTimeResult result, ref DateTimeRawInfo raw)
 {
     if (result.Month == -1)
     {
         //Should have a month suffix
         result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
         return false;
     }
     if (result.Year != -1)
     {
         // Aleady has a year suffix
         result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
         return false;
     }
     if (!TryAdjustYear(ref result, raw.GetNumber(0), out result.Year))
     {
         // the year value is out of range
         result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
         return false;            
     }
     result.Day = 1;
     return true;
 }
		private static bool GetDateOfNNDS(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
		{
			if ((result.flags & ParseFlags.HaveYear) != (ParseFlags)0)
			{
				if ((result.flags & ParseFlags.HaveMonth) == (ParseFlags)0 && (result.flags & ParseFlags.HaveDay) == (ParseFlags)0 && DateTimeParse.SetDateYMD(ref result, result.Year = DateTimeParse.AdjustYear(ref result, raw.year), raw.GetNumber(0), raw.GetNumber(1)))
				{
					return true;
				}
			}
			else
			{
				if ((result.flags & ParseFlags.HaveMonth) != (ParseFlags)0 && (result.flags & ParseFlags.HaveYear) == (ParseFlags)0 && (result.flags & ParseFlags.HaveDay) == (ParseFlags)0)
				{
					int num;
					if (!DateTimeParse.GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out num))
					{
						result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
						return false;
					}
					if (num == 0)
					{
						if (DateTimeParse.SetDateYMD(ref result, DateTimeParse.AdjustYear(ref result, raw.GetNumber(0)), result.Month, raw.GetNumber(1)))
						{
							return true;
						}
					}
					else
					{
						if (DateTimeParse.SetDateYMD(ref result, DateTimeParse.AdjustYear(ref result, raw.GetNumber(1)), result.Month, raw.GetNumber(0)))
						{
							return true;
						}
					}
				}
			}
			result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
			return false;
		}
示例#28
0
        private static Boolean GetDateOfNNDS(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
        {

            // For partial CJK Dates, the only valid formats are with a specified year, followed by two numbers, which
            // will be the Month and Day, and with a specified Month, when the numbers are either the year and day or
            // day and year, depending on the short date pattern.

            if ((result.flags & ParseFlags.HaveYear) != 0) {
                if (((result.flags & ParseFlags.HaveMonth) == 0) && ((result.flags & ParseFlags.HaveDay) == 0)) {
                    if (TryAdjustYear(ref result, raw.year, out result.Year) && SetDateYMD(ref result, result.Year, raw.GetNumber(0), raw.GetNumber(1))) {
                        return true;
                    }
                }
            }
            else if ((result.flags & ParseFlags.HaveMonth) != 0) {
                if (((result.flags & ParseFlags.HaveYear) == 0) && ((result.flags & ParseFlags.HaveDay) == 0)) {
                    int order;
                    if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out order)) {
                        result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
                        return false;
                    }
                    int year;
                    if (order == ORDER_YMD) {
                        if (TryAdjustYear(ref result, raw.GetNumber(0), out year) && SetDateYMD(ref result, year, result.Month, raw.GetNumber(1))) {
                            return true;
                        }
                    }
                    else {
                        if (TryAdjustYear(ref result, raw.GetNumber(1), out year) && SetDateYMD(ref result, year, result.Month, raw.GetNumber(0))){
                            return true;
                        }
                    }
                }
            }
            result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
            return false;
        }
		private static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, ref DateTimeResult result)
		{
			if (raw.year >= 0 && raw.GetNumber(0) >= 0)
			{
				raw.GetNumber(1);
			}
			str.Index--;
			int second = 0;
			double num = 0.0;
			str.SkipWhiteSpaces();
			int hour;
			if (!DateTimeParse.ParseDigits(ref str, 2, out hour))
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			str.SkipWhiteSpaces();
			if (!str.Match(':'))
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			str.SkipWhiteSpaces();
			int minute;
			if (!DateTimeParse.ParseDigits(ref str, 2, out minute))
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			str.SkipWhiteSpaces();
			if (str.Match(':'))
			{
				str.SkipWhiteSpaces();
				if (!DateTimeParse.ParseDigits(ref str, 2, out second))
				{
					result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
					return false;
				}
				if (str.Match('.'))
				{
					if (!DateTimeParse.ParseFraction(ref str, out num))
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					str.Index--;
				}
				str.SkipWhiteSpaces();
			}
			if (str.GetNext())
			{
				char @char = str.GetChar();
				if (@char == '+' || @char == '-')
				{
					result.flags |= ParseFlags.TimeZoneUsed;
					if (!DateTimeParse.ParseTimeZone(ref str, ref result.timeZoneOffset))
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
				}
				else
				{
					if (@char == 'Z' || @char == 'z')
					{
						result.flags |= ParseFlags.TimeZoneUsed;
						result.timeZoneOffset = TimeSpan.Zero;
						result.flags |= ParseFlags.TimeZoneUtc;
					}
					else
					{
						str.Index--;
					}
				}
				str.SkipWhiteSpaces();
				if (str.Match('#'))
				{
					if (!DateTimeParse.VerifyValidPunctuation(ref str))
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					str.SkipWhiteSpaces();
				}
				if (str.Match('\0') && !DateTimeParse.VerifyValidPunctuation(ref str))
				{
					result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
					return false;
				}
				if (str.GetNext())
				{
					result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
					return false;
				}
			}
			Calendar defaultInstance = GregorianCalendar.GetDefaultInstance();
			DateTime parsedDate;
			if (!defaultInstance.TryToDateTime(raw.year, raw.GetNumber(0), raw.GetNumber(1), hour, minute, second, 0, result.era, out parsedDate))
			{
				result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
				return false;
			}
			parsedDate = parsedDate.AddTicks((long)Math.Round(num * 10000000.0));
			result.parsedDate = parsedDate;
			return DateTimeParse.DetermineTimeZoneAdjustments(ref result, styles, false);
		}
示例#30
0
 private static bool GetDayOfNNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
 {
     int num4;
     if ((result.flags & ParseFlags.HaveDate) != 0)
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
         return false;
     }
     int number = raw.GetNumber(0);
     int month = raw.GetNumber(1);
     int day = raw.GetNumber(2);
     if (!GetYearMonthDayOrder(dtfi.ShortDatePattern, dtfi, out num4))
     {
         result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadDatePattern", dtfi.ShortDatePattern);
         return false;
     }
     if (num4 == 0)
     {
         if (SetDateYMD(ref result, AdjustYear(ref result, number), month, day))
         {
             result.flags |= ParseFlags.HaveDate;
             return true;
         }
     }
     else if (num4 == 1)
     {
         if (SetDateMDY(ref result, number, month, AdjustYear(ref result, day)))
         {
             result.flags |= ParseFlags.HaveDate;
             return true;
         }
     }
     else if (num4 == 2)
     {
         if (SetDateDMY(ref result, number, month, AdjustYear(ref result, day)))
         {
             result.flags |= ParseFlags.HaveDate;
             return true;
         }
     }
     else if ((num4 == 3) && SetDateYDM(ref result, AdjustYear(ref result, number), month, day))
     {
         result.flags |= ParseFlags.HaveDate;
         return true;
     }
     result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
     return false;
 }