/// <summary> /// Parses a <see cref="Match"/> into a <see cref="DateToken"/>. /// </summary> /// <param name="match">A <see cref="Match"/> representation of a <see cref="DateToken"/>.</param> /// <param name="provider">An <see cref="IFormatProvider"/>.</param> /// <returns>The <see cref="DateToken"/> parsed from the <see cref="Match"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="match"/> or <paramref name="provider"/> is /// <c>null</c>.</exception> /// <exception cref="FormatException">If the <paramref name="match"/> is not a supported representation of /// a <see cref="DateToken"/>.</exception> protected override DateToken ParseInternal(Match match, IFormatProvider provider) { NormalDateToken dateToken = new NormalDateToken(); provider = Resources.ResourceManager.GetEffectiveProvider(provider); // Parse day if (match.Groups["day"].Success) { dateToken.Day = int.Parse(match.Groups["day"].Value, provider); } // Parse month if (match.Groups["month"].Success) { int month; if (int.TryParse(match.Groups["month"].Value, NumberStyles.None, provider, out month)) { dateToken.Month = month; } else { dateToken.Month = DateTimeExtensions.ParseMonth(match.Groups["month"].Value, provider); } } // Parse year if (match.Groups["year"].Success) { dateToken.Year = int.Parse(match.Groups["year"].Value, provider); if (dateToken.Year.Value < 100) { dateToken.Year += 2000; } } return(dateToken); }
/// <summary> /// Parses a <see cref="Match"/> into a <see cref="DateToken"/>. /// </summary> /// <param name="match">A <see cref="Match"/> representation of a <see cref="DateToken"/>.</param> /// <param name="provider">An <see cref="IFormatProvider"/>.</param> /// <returns>The <see cref="DateToken"/> parsed from the <see cref="Match"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="match"/> or <paramref name="provider"/> is /// <c>null</c>.</exception> /// <exception cref="FormatException">If the <paramref name="match"/> is not a supported representation of /// a <see cref="DateToken"/>.</exception> protected override DateToken ParseInternal(Match match, IFormatProvider provider) { NormalDateToken dateToken = new NormalDateToken(); provider = Resources.ResourceManager.GetEffectiveProvider(provider); // Parse day if (match.Groups["day"].Success) { dateToken.Day = int.Parse(match.Groups["day"].Value, provider); } // Parse month if (match.Groups["month"].Success) { int month; if (int.TryParse(match.Groups["month"].Value, NumberStyles.None, provider, out month)) { dateToken.Month = month; } else { dateToken.Month = DateTimeExtensions.ParseMonth(match.Groups["month"].Value, provider); } } // Parse year if (match.Groups["year"].Success) { dateToken.Year = int.Parse(match.Groups["year"].Value, provider); if (dateToken.Year.Value < 100) { dateToken.Year += 2000; } } return dateToken; }