Пример #1
0
        public static bool TryParse(string input, IFormatProvider formatProvider, DateTimeStyles styles, out DateTimeOffset result)
        {
            styles = ValidateStyles(styles, nameof(styles));
            if (input == null)
            {
                result = default;
                return(false);
            }

            TimeSpan offset;
            DateTime dateResult;
            bool     parsed = DateTimeParse.TryParse(input,
                                                     DateTimeFormatInfo.GetInstance(formatProvider),
                                                     styles,
                                                     out dateResult,
                                                     out offset);

            result = new DateTimeOffset(dateResult.Ticks, offset);
            return(parsed);
        }
Пример #2
0
        // Constructs a DateTimeOffset from a string. The string must specify a
        // date and optionally a time in a culture-specific or universal format.
        // Leading and trailing whitespace characters are allowed.
        //
        public static DateTimeOffset ParseExact(string input, string format, IFormatProvider?formatProvider, DateTimeStyles styles)
        {
            styles = ValidateStyles(styles, nameof(styles));
            if (input == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
            }
            if (format == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format);
            }

            DateTime dateResult = DateTimeParse.ParseExact(input,
                                                           format,
                                                           DateTimeFormatInfo.GetInstance(formatProvider),
                                                           styles,
                                                           out TimeSpan offset);

            return(new DateTimeOffset(dateResult.Ticks, offset));
        }
Пример #3
0
        public static bool TryParseExact([NotNullWhen(true)] string?input, [NotNullWhen(true)] string?[]?formats, IFormatProvider?formatProvider, DateTimeStyles styles,
                                         out DateTimeOffset result)
        {
            styles = ValidateStyles(styles, nameof(styles));
            if (input == null)
            {
                result = default;
                return(false);
            }

            bool parsed = DateTimeParse.TryParseExactMultiple(input,
                                                              formats,
                                                              DateTimeFormatInfo.GetInstance(formatProvider),
                                                              styles,
                                                              out DateTime dateResult,
                                                              out TimeSpan offset);

            result = new DateTimeOffset(dateResult.Ticks, offset);
            return(parsed);
        }
Пример #4
0
 internal TokenType GetSeparatorToken(DateTimeFormatInfo dtfi, out int indexBeforeSeparator, out char charBeforeSeparator)
 {
     indexBeforeSeparator = this.Index;
     charBeforeSeparator  = this.m_current;
     if (!this.SkipWhiteSpaceCurrent())
     {
         return(TokenType.SEP_End);
     }
     if (!DateTimeParse.IsDigit(this.m_current))
     {
         TokenType type;
         int       num;
         if (!dtfi.Tokenize(TokenType.SeparatorTokenMask, out type, out num, ref this))
         {
             type = TokenType.SEP_Space;
         }
         return(type);
     }
     return(TokenType.SEP_Space);
 }
Пример #5
0
        public static Boolean TryParseExact(String input, String[] formats, IFormatProvider formatProvider, DateTimeStyles styles,
                                            out DateTimeOffset result)
        {
            styles = ValidateStyles(styles, nameof(styles));
            if (input == null)
            {
                result = default(DateTimeOffset);
                return(false);
            }

            TimeSpan offset;
            DateTime dateResult;
            Boolean  parsed = DateTimeParse.TryParseExactMultiple(input.AsReadOnlySpan(),
                                                                  formats,
                                                                  DateTimeFormatInfo.GetInstance(formatProvider),
                                                                  styles,
                                                                  out dateResult,
                                                                  out offset);

            result = new DateTimeOffset(dateResult.Ticks, offset);
            return(parsed);
        }
Пример #6
0
 public static DateTime ParseExact(String s, String[] formats, IFormatProvider provider, DateTimeStyles style)
 {
     DateTimeFormatInfo.ValidateStyles(style, "style");
     return(DateTimeParse.ParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style));
 }
Пример #7
0
 // Constructs a DateTime from a string. The string must specify a
 // date and optionally a time in a culture-specific or universal format.
 // Leading and trailing whitespace characters are allowed.
 //
 public static DateTime ParseExact(String s, String format, IFormatProvider provider)
 {
     return(DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None));
 }
		internal static void TPTraceExit(string message, DateTimeParse.DS dps)
		{
		}
		private static bool MatchAbbreviatedTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref DateTimeParse.TM result)
		{
			if (str.GetNext())
			{
				if (str.GetChar() == dtfi.AMDesignator[0])
				{
					result = DateTimeParse.TM.AM;
					return true;
				}
				if (str.GetChar() == dtfi.PMDesignator[0])
				{
					result = DateTimeParse.TM.PM;
					return true;
				}
			}
			return false;
		}
		internal static bool ProcessTerminaltState(DateTimeParse.DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi)
		{
			bool flag = true;
			switch (dps)
			{
				case DateTimeParse.DS.DX_NN:
				{
					flag = DateTimeParse.GetDayOfNN(ref result, ref styles, ref raw, dtfi);
					break;
				}
				case DateTimeParse.DS.DX_NNN:
				{
					flag = DateTimeParse.GetDayOfNNN(ref result, ref raw, dtfi);
					break;
				}
				case DateTimeParse.DS.DX_MN:
				{
					flag = DateTimeParse.GetDayOfMN(ref result, ref styles, ref raw, dtfi);
					break;
				}
				case DateTimeParse.DS.DX_NM:
				{
					flag = DateTimeParse.GetDayOfNM(ref result, ref styles, ref raw, dtfi);
					break;
				}
				case DateTimeParse.DS.DX_MNN:
				{
					flag = DateTimeParse.GetDayOfMNN(ref result, ref raw, dtfi);
					break;
				}
				case DateTimeParse.DS.DX_DS:
				{
					flag = true;
					break;
				}
				case DateTimeParse.DS.DX_DSN:
				{
					flag = DateTimeParse.GetDateOfDSN(ref result, ref raw);
					break;
				}
				case DateTimeParse.DS.DX_NDS:
				{
					flag = DateTimeParse.GetDateOfNDS(ref result, ref raw);
					break;
				}
				case DateTimeParse.DS.DX_NNDS:
				{
					flag = DateTimeParse.GetDateOfNNDS(ref result, ref raw, dtfi);
					break;
				}
				case DateTimeParse.DS.DX_YNN:
				{
					flag = DateTimeParse.GetDayOfYNN(ref result, ref raw, dtfi);
					break;
				}
				case DateTimeParse.DS.DX_YMN:
				{
					flag = DateTimeParse.GetDayOfYMN(ref result, ref raw, dtfi);
					break;
				}
				case DateTimeParse.DS.DX_YN:
				{
					flag = DateTimeParse.GetDayOfYN(ref result, ref raw, dtfi);
					break;
				}
				case DateTimeParse.DS.DX_YM:
				{
					flag = DateTimeParse.GetDayOfYM(ref result, ref raw, dtfi);
					break;
				}
				case DateTimeParse.DS.TX_N:
				{
					flag = DateTimeParse.GetTimeOfN(dtfi, ref result, ref raw);
					break;
				}
				case DateTimeParse.DS.TX_NN:
				{
					flag = DateTimeParse.GetTimeOfNN(dtfi, ref result, ref raw);
					break;
				}
				case DateTimeParse.DS.TX_NNN:
				{
					flag = DateTimeParse.GetTimeOfNNN(dtfi, ref result, ref raw);
					break;
				}
				case DateTimeParse.DS.TX_TS:
				{
					flag = true;
					break;
				}
				case DateTimeParse.DS.DX_NNY:
				{
					flag = DateTimeParse.GetDayOfNNY(ref result, ref raw, dtfi);
					break;
				}
			}
			if (!flag)
			{
				return false;
			}
			if (dps > DateTimeParse.DS.ERROR)
			{
				raw.numCount = 0;
			}
			return true;
		}
Пример #11
0
 public static bool TryParse(string s, IFormatProvider provider, DateTimeStyles styles, out DateTime result)
 {
     DateTimeFormatInfo.ValidateStyles(styles, "styles");
     return(DateTimeParse.TryParse(s, DateTimeFormatInfo.GetInstance(provider), styles, out result));
 }
Пример #12
0
 public static bool TryParse(string s, out DateTime result)
 {
     return(DateTimeParse.TryParse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out result));
 }
        internal void GetRegularToken(out TokenType tokenType, out int tokenValue, DateTimeFormatInfo dtfi)
        {
            tokenValue = 0;
            if (this.Index >= this.len)
            {
                tokenType = TokenType.EndOfString;
                return;
            }
            tokenType = TokenType.UnknownToken;
IL_19:
            while (!DateTimeParse.IsDigit(this.m_current))
            {
                if (char.IsWhiteSpace(this.m_current))
                {
                    for (;;)
                    {
                        int num = this.Index + 1;
                        this.Index = num;
                        if (num >= this.len)
                        {
                            break;
                        }
                        this.m_current = this.Value[this.Index];
                        if (!char.IsWhiteSpace(this.m_current))
                        {
                            goto IL_19;
                        }
                    }
                    tokenType = TokenType.EndOfString;
                    return;
                }
                dtfi.Tokenize(TokenType.RegularTokenMask, out tokenType, out tokenValue, ref this);
                return;
            }
            tokenValue = (int)(this.m_current - '0');
            int index = this.Index;

            for (;;)
            {
                int num = this.Index + 1;
                this.Index = num;
                if (num >= this.len)
                {
                    break;
                }
                this.m_current = this.Value[this.Index];
                int num2 = (int)(this.m_current - '0');
                if (num2 < 0 || num2 > 9)
                {
                    break;
                }
                tokenValue = tokenValue * 10 + num2;
            }
            if (this.Index - index > 8)
            {
                tokenType  = TokenType.NumberToken;
                tokenValue = -1;
            }
            else if (this.Index - index < 3)
            {
                tokenType = TokenType.NumberToken;
            }
            else
            {
                tokenType = TokenType.YearNumberToken;
            }
            if (!this.m_checkDigitToken)
            {
                return;
            }
            int  index2  = this.Index;
            char current = this.m_current;

            this.Index     = index;
            this.m_current = this.Value[this.Index];
            TokenType tokenType2;
            int       num3;

            if (dtfi.Tokenize(TokenType.RegularTokenMask, out tokenType2, out num3, ref this))
            {
                tokenType  = tokenType2;
                tokenValue = num3;
                return;
            }
            this.Index     = index2;
            this.m_current = current;
        }
Пример #14
0
        public static DateTimeOffset Parse(string input)
        {
            TimeSpan span;

            return(new DateTimeOffset(DateTimeParse.Parse(input, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out span).Ticks, span));
        }
Пример #15
0
        internal void GetRegularToken(out TokenType tokenType, out int tokenValue, DateTimeFormatInfo dtfi)
        {
            tokenValue = 0;
            if (this.Index >= this.len)
            {
                tokenType = TokenType.EndOfString;
                return;
            }
            tokenType = TokenType.UnknownToken;
Label_0019:
            if (!DateTimeParse.IsDigit(this.m_current))
            {
                if (char.IsWhiteSpace(this.m_current))
                {
                    while (++this.Index < this.len)
                    {
                        this.m_current = this.Value[this.Index];
                        if (!char.IsWhiteSpace(this.m_current))
                        {
                            goto Label_0019;
                        }
                    }
                    tokenType = TokenType.EndOfString;
                    return;
                }
                dtfi.Tokenize(TokenType.RegularTokenMask, out tokenType, out tokenValue, ref this);
            }
            else
            {
                tokenValue = this.m_current - '0';
                int index = this.Index;
                while (++this.Index < this.len)
                {
                    this.m_current = this.Value[this.Index];
                    int num = this.m_current - '0';
                    if ((num < 0) || (num > 9))
                    {
                        break;
                    }
                    tokenValue = (tokenValue * 10) + num;
                }
                if ((this.Index - index) > 8)
                {
                    tokenType  = TokenType.NumberToken;
                    tokenValue = -1;
                }
                else if ((this.Index - index) < 3)
                {
                    tokenType = TokenType.NumberToken;
                }
                else
                {
                    tokenType = TokenType.YearNumberToken;
                }
                if (this.m_checkDigitToken)
                {
                    TokenType type;
                    int       num4;
                    int       num3    = this.Index;
                    char      current = this.m_current;
                    this.Index     = index;
                    this.m_current = this.Value[this.Index];
                    if (dtfi.Tokenize(TokenType.RegularTokenMask, out type, out num4, ref this))
                    {
                        tokenType  = type;
                        tokenValue = num4;
                        return;
                    }
                    this.Index     = num3;
                    this.m_current = current;
                }
            }
        }
		private static bool AdjustHour(ref int hour, DateTimeParse.TM timeMark)
		{
			if (timeMark != DateTimeParse.TM.NotSet)
			{
				if (timeMark == DateTimeParse.TM.AM)
				{
					if (hour < 0 || hour > 12)
					{
						return false;
					}
					hour = ((hour == 12) ? 0 : hour);
				}
				else
				{
					if (hour < 0 || hour > 23)
					{
						return false;
					}
					if (hour < 12)
					{
						hour += 12;
					}
				}
			}
			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;
		}
Пример #18
0
 public static bool TryParseExact(string s, string[] formats, IFormatProvider provider, DateTimeStyles style, out DateTime result)
 {
     DateTimeFormatInfo.ValidateStyles(style, "style");
     return(DateTimeParse.TryParseExactMultiple(s, formats, DateTimeFormatInfo.GetInstance(provider), style, out result));
 }
		private static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref DateTimeParse.TM result)
		{
			result = DateTimeParse.TM.NotSet;
			if (dtfi.AMDesignator.Length == 0)
			{
				result = DateTimeParse.TM.AM;
			}
			if (dtfi.PMDesignator.Length == 0)
			{
				result = DateTimeParse.TM.PM;
			}
			if (str.GetNext())
			{
				string text = dtfi.AMDesignator;
				if (text.Length > 0 && str.MatchSpecifiedWord(text))
				{
					str.Index += text.Length - 1;
					result = DateTimeParse.TM.AM;
					return true;
				}
				text = dtfi.PMDesignator;
				if (text.Length > 0 && str.MatchSpecifiedWord(text))
				{
					str.Index += text.Length - 1;
					result = DateTimeParse.TM.PM;
					return true;
				}
				str.Index--;
			}
			return result != -1;
		}
Пример #20
0
 public static DateTime Parse(string s, IFormatProvider provider)
 {
     return(DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None));
 }
		internal static void PTSTraceExit(DateTimeParse.DS dps, bool passed)
		{
		}
Пример #22
0
 // Constructs a DateTime from a string. The string must specify a
 // date and optionally a time in a culture-specific or universal format.
 // Leading and trailing whitespace characters are allowed.
 //
 public static DateTime Parse(String s)
 {
     return(DateTimeParse.Parse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None));
 }
		private static bool Lex(DateTimeParse.DS dps, ref __DTString str, ref DateTimeToken dtok, ref DateTimeRawInfo raw, ref DateTimeResult result, ref DateTimeFormatInfo dtfi)
		{
			dtok.dtt = DateTimeParse.DTT.Unk;
			TokenType tokenType;
			int num;
			str.GetRegularToken(out tokenType, out num, dtfi);
			switch (tokenType)
			{
				case TokenType.NumberToken:
				case TokenType.YearNumberToken:
				{
					if (raw.numCount == 3 || num == -1)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					if (dps == DateTimeParse.DS.T_NNt && str.Index < str.len - 1)
					{
						char c = str.Value[str.Index];
						if (c == '.')
						{
							DateTimeParse.ParseFraction(ref str, out raw.fraction);
						}
					}
					if ((dps == DateTimeParse.DS.T_NNt || dps == DateTimeParse.DS.T_Nt) && str.Index < str.len - 1 && !DateTimeParse.HandleTimeZone(ref str, ref result))
					{
						return false;
					}
					dtok.num = num;
					if (tokenType != TokenType.YearNumberToken)
					{
						int index;
						char current;
						TokenType separatorToken;
						TokenType tokenType2 = separatorToken = str.GetSeparatorToken(dtfi, out index, out current);
						if (separatorToken > TokenType.SEP_YearSuff)
						{
							if (separatorToken <= TokenType.SEP_HourSuff)
							{
								if (separatorToken == TokenType.SEP_MonthSuff || separatorToken == TokenType.SEP_DaySuff)
								{
									dtok.dtt = DateTimeParse.DTT.NumDatesuff;
									dtok.suffix = tokenType2;
									break;
								}
								if (separatorToken != TokenType.SEP_HourSuff)
								{
									goto IL_52A;
								}
							}
							else
							{
								if (separatorToken <= TokenType.SEP_SecondSuff)
								{
									if (separatorToken != TokenType.SEP_MinuteSuff && separatorToken != TokenType.SEP_SecondSuff)
									{
										goto IL_52A;
									}
								}
								else
								{
									if (separatorToken == TokenType.SEP_LocalTimeMark)
									{
										dtok.dtt = DateTimeParse.DTT.NumLocalTimeMark;
										raw.AddNumber(dtok.num);
										break;
									}
									if (separatorToken != TokenType.SEP_DateOrOffset)
									{
										goto IL_52A;
									}
									if (DateTimeParse.dateParsingStates[(int)dps][4] == DateTimeParse.DS.ERROR && DateTimeParse.dateParsingStates[(int)dps][3] > DateTimeParse.DS.ERROR)
									{
										str.Index = index;
										str.m_current = current;
										dtok.dtt = DateTimeParse.DTT.NumSpace;
									}
									else
									{
										dtok.dtt = DateTimeParse.DTT.NumDatesep;
									}
									raw.AddNumber(dtok.num);
									break;
								}
							}
							dtok.dtt = DateTimeParse.DTT.NumTimesuff;
							dtok.suffix = tokenType2;
							break;
						}
						if (separatorToken <= TokenType.SEP_Am)
						{
							if (separatorToken == TokenType.SEP_End)
							{
								dtok.dtt = DateTimeParse.DTT.NumEnd;
								raw.AddNumber(dtok.num);
								break;
							}
							if (separatorToken == TokenType.SEP_Space)
							{
								dtok.dtt = DateTimeParse.DTT.NumSpace;
								raw.AddNumber(dtok.num);
								break;
							}
							if (separatorToken != TokenType.SEP_Am)
							{
								goto IL_52A;
							}
						}
						else
						{
							if (separatorToken <= TokenType.SEP_Date)
							{
								if (separatorToken != TokenType.SEP_Pm)
								{
									if (separatorToken != TokenType.SEP_Date)
									{
										goto IL_52A;
									}
									dtok.dtt = DateTimeParse.DTT.NumDatesep;
									raw.AddNumber(dtok.num);
									break;
								}
							}
							else
							{
								if (separatorToken == TokenType.SEP_Time)
								{
									dtok.dtt = DateTimeParse.DTT.NumTimesep;
									raw.AddNumber(dtok.num);
									break;
								}
								if (separatorToken != TokenType.SEP_YearSuff)
								{
									goto IL_52A;
								}
								dtok.num = dtfi.Calendar.ToFourDigitYear(num);
								dtok.dtt = DateTimeParse.DTT.NumDatesuff;
								dtok.suffix = tokenType2;
								break;
							}
						}
						if (raw.timeMark != DateTimeParse.TM.NotSet)
						{
							result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
							break;
						}
						raw.timeMark = ((tokenType2 == TokenType.SEP_Am) ? DateTimeParse.TM.AM : DateTimeParse.TM.PM);
						dtok.dtt = DateTimeParse.DTT.NumAmpm;
						raw.AddNumber(dtok.num);
						if ((dps == DateTimeParse.DS.T_NNt || dps == DateTimeParse.DS.T_Nt) && !DateTimeParse.HandleTimeZone(ref str, ref result))
						{
							return false;
						}
						break;
						IL_52A:
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					if (raw.year == -1)
					{
						raw.year = num;
						int index;
						char current;
						TokenType separatorToken2;
						TokenType tokenType2 = separatorToken2 = str.GetSeparatorToken(dtfi, out index, out current);
						if (separatorToken2 > TokenType.SEP_YearSuff)
						{
							if (separatorToken2 <= TokenType.SEP_HourSuff)
							{
								if (separatorToken2 == TokenType.SEP_MonthSuff || separatorToken2 == TokenType.SEP_DaySuff)
								{
									goto IL_26A;
								}
								if (separatorToken2 != TokenType.SEP_HourSuff)
								{
									goto IL_28E;
								}
							}
							else
							{
								if (separatorToken2 != TokenType.SEP_MinuteSuff && separatorToken2 != TokenType.SEP_SecondSuff)
								{
									if (separatorToken2 != TokenType.SEP_DateOrOffset)
									{
										goto IL_28E;
									}
									if (DateTimeParse.dateParsingStates[(int)dps][13] == DateTimeParse.DS.ERROR && DateTimeParse.dateParsingStates[(int)dps][12] > DateTimeParse.DS.ERROR)
									{
										str.Index = index;
										str.m_current = current;
										dtok.dtt = DateTimeParse.DTT.YearSpace;
										return true;
									}
									dtok.dtt = DateTimeParse.DTT.YearDateSep;
									return true;
								}
							}
							dtok.dtt = DateTimeParse.DTT.NumTimesuff;
							dtok.suffix = tokenType2;
							return true;
						}
						if (separatorToken2 <= TokenType.SEP_Am)
						{
							if (separatorToken2 == TokenType.SEP_End)
							{
								dtok.dtt = DateTimeParse.DTT.YearEnd;
								return true;
							}
							if (separatorToken2 == TokenType.SEP_Space)
							{
								dtok.dtt = DateTimeParse.DTT.YearSpace;
								return true;
							}
							if (separatorToken2 != TokenType.SEP_Am)
							{
								goto IL_28E;
							}
						}
						else
						{
							if (separatorToken2 != TokenType.SEP_Pm)
							{
								if (separatorToken2 == TokenType.SEP_Date)
								{
									dtok.dtt = DateTimeParse.DTT.YearDateSep;
									return true;
								}
								if (separatorToken2 != TokenType.SEP_YearSuff)
								{
									goto IL_28E;
								}
								goto IL_26A;
							}
						}
						if (raw.timeMark == DateTimeParse.TM.NotSet)
						{
							raw.timeMark = ((tokenType2 == TokenType.SEP_Am) ? DateTimeParse.TM.AM : DateTimeParse.TM.PM);
							dtok.dtt = DateTimeParse.DTT.YearSpace;
							return true;
						}
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return true;
						IL_26A:
						dtok.dtt = DateTimeParse.DTT.NumDatesuff;
						dtok.suffix = tokenType2;
						return true;
						IL_28E:
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
					return false;
				}
				case TokenType.Am:
				case TokenType.Pm:
				{
					if (raw.timeMark != DateTimeParse.TM.NotSet)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					raw.timeMark = (DateTimeParse.TM)num;
					break;
				}
				case TokenType.MonthToken:
				{
					if (raw.month != -1)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					int index;
					char current;
					TokenType separatorToken3 = str.GetSeparatorToken(dtfi, out index, out current);
					if (separatorToken3 <= TokenType.SEP_Space)
					{
						if (separatorToken3 == TokenType.SEP_End)
						{
							dtok.dtt = DateTimeParse.DTT.MonthEnd;
							goto IL_786;
						}
						if (separatorToken3 == TokenType.SEP_Space)
						{
							dtok.dtt = DateTimeParse.DTT.MonthSpace;
							goto IL_786;
						}
					}
					else
					{
						if (separatorToken3 == TokenType.SEP_Date)
						{
							dtok.dtt = DateTimeParse.DTT.MonthDatesep;
							goto IL_786;
						}
						if (separatorToken3 == TokenType.SEP_DateOrOffset)
						{
							if (DateTimeParse.dateParsingStates[(int)dps][8] == DateTimeParse.DS.ERROR && DateTimeParse.dateParsingStates[(int)dps][7] > DateTimeParse.DS.ERROR)
							{
								str.Index = index;
								str.m_current = current;
								dtok.dtt = DateTimeParse.DTT.MonthSpace;
								goto IL_786;
							}
							dtok.dtt = DateTimeParse.DTT.MonthDatesep;
							goto IL_786;
						}
					}
					result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
					return false;
					IL_786:
					raw.month = num;
					break;
				}
				case TokenType.EndOfString:
				{
					dtok.dtt = DateTimeParse.DTT.End;
					break;
				}
				case TokenType.DayOfWeekToken:
				{
					if (raw.dayOfWeek != -1)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					raw.dayOfWeek = num;
					dtok.dtt = DateTimeParse.DTT.DayOfWeek;
					break;
				}
				case TokenType.TimeZoneToken:
				{
					if ((result.flags & ParseFlags.TimeZoneUsed) != (ParseFlags)0)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					dtok.dtt = DateTimeParse.DTT.TimeZone;
					result.flags |= ParseFlags.TimeZoneUsed;
					result.timeZoneOffset = new TimeSpan(0L);
					result.flags |= ParseFlags.TimeZoneUtc;
					break;
				}
				case TokenType.EraToken:
				{
					if (result.era == -1)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					result.era = num;
					dtok.dtt = DateTimeParse.DTT.Era;
					break;
				}
				case TokenType.UnknownToken:
				{
					if (char.IsLetter(str.m_current))
					{
						result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_UnknowDateTimeWord", str.Index);
						return false;
					}
					if (Environment.GetCompatibilityFlag(CompatibilityFlag.DateTimeParseIgnorePunctuation) && (result.flags & ParseFlags.CaptureOffset) == (ParseFlags)0)
					{
						str.GetNext();
						return true;
					}
					if ((str.m_current == '-' || str.m_current == '+') && (result.flags & ParseFlags.TimeZoneUsed) == (ParseFlags)0)
					{
						int index2 = str.Index;
						if (DateTimeParse.ParseTimeZone(ref str, ref result.timeZoneOffset))
						{
							result.flags |= ParseFlags.TimeZoneUsed;
							return true;
						}
						str.Index = index2;
					}
					if (DateTimeParse.VerifyValidPunctuation(ref str))
					{
						return true;
					}
					result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
					return false;
				}
				case TokenType.HebrewNumber:
				{
					int index;
					char current;
					if (num < 100)
					{
						dtok.num = num;
						raw.AddNumber(dtok.num);
						TokenType separatorToken4 = str.GetSeparatorToken(dtfi, out index, out current);
						if (separatorToken4 <= TokenType.SEP_Space)
						{
							if (separatorToken4 == TokenType.SEP_End)
							{
								dtok.dtt = DateTimeParse.DTT.NumEnd;
								break;
							}
							if (separatorToken4 != TokenType.SEP_Space)
							{
								goto IL_695;
							}
						}
						else
						{
							if (separatorToken4 != TokenType.SEP_Date)
							{
								if (separatorToken4 != TokenType.SEP_DateOrOffset)
								{
									goto IL_695;
								}
								if (DateTimeParse.dateParsingStates[(int)dps][4] == DateTimeParse.DS.ERROR && DateTimeParse.dateParsingStates[(int)dps][3] > DateTimeParse.DS.ERROR)
								{
									str.Index = index;
									str.m_current = current;
									dtok.dtt = DateTimeParse.DTT.NumSpace;
									break;
								}
								dtok.dtt = DateTimeParse.DTT.NumDatesep;
								break;
							}
						}
						dtok.dtt = DateTimeParse.DTT.NumDatesep;
						break;
						IL_695:
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					if (raw.year != -1)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					raw.year = num;
					TokenType separatorToken5 = str.GetSeparatorToken(dtfi, out index, out current);
					if (separatorToken5 != TokenType.SEP_End)
					{
						if (separatorToken5 != TokenType.SEP_Space)
						{
							if (separatorToken5 == TokenType.SEP_DateOrOffset)
							{
								if (DateTimeParse.dateParsingStates[(int)dps][12] > DateTimeParse.DS.ERROR)
								{
									str.Index = index;
									str.m_current = current;
									dtok.dtt = DateTimeParse.DTT.YearSpace;
									break;
								}
							}
							result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
							return false;
						}
						dtok.dtt = DateTimeParse.DTT.YearSpace;
					}
					else
					{
						dtok.dtt = DateTimeParse.DTT.YearEnd;
					}
					break;
				}
				case TokenType.JapaneseEraToken:
				{
					result.calendar = JapaneseCalendar.GetDefaultInstance();
					dtfi = DateTimeFormatInfo.GetJapaneseCalendarDTFI();
					if (result.era == -1)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					result.era = num;
					dtok.dtt = DateTimeParse.DTT.Era;
					break;
				}
				case TokenType.TEraToken:
				{
					result.calendar = TaiwanCalendar.GetDefaultInstance();
					dtfi = DateTimeFormatInfo.GetTaiwanCalendarDTFI();
					if (result.era == -1)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					result.era = num;
					dtok.dtt = DateTimeParse.DTT.Era;
					break;
				}
			}
			return true;
		}
Пример #24
0
 public static DateTime Parse(String s, IFormatProvider provider, DateTimeStyles styles)
 {
     DateTimeFormatInfo.ValidateStyles(styles, "styles");
     return(DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), styles));
 }