/// <summary> /// Parses a <see cref="Match"/> into a <see cref="TimeToken"/>. /// </summary> /// <param name="match">A <see cref="Match"/> representation of a <see cref="TimeToken"/>.</param> /// <param name="provider">An <see cref="IFormatProvider"/>.</param> /// <returns>The <see cref="TimeToken"/> 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="TimeToken"/>.</exception> protected override TimeToken ParseInternal(Match match, IFormatProvider provider) { NormalTimeToken timeToken = new NormalTimeToken(); provider = Resources.ResourceManager.GetEffectiveProvider(provider); // Parse hour if (match.Groups["hour"].Success) { timeToken.Hour = int.Parse(match.Groups["hour"].Value, provider); } // Parse minute if (match.Groups["minute"].Success) { timeToken.Minute = int.Parse(match.Groups["minute"].Value, provider); } // Parse second if (match.Groups["second"].Success) { timeToken.Second = int.Parse(match.Groups["second"].Value, provider); } // Parse hour period if (match.Groups["am"].Success) { timeToken.HourPeriod = HourPeriod.Am; } else if (match.Groups["pm"].Success) { timeToken.HourPeriod = HourPeriod.Pm; } else if (match.Groups["military"].Success) { if (timeToken.Hour == 0) { timeToken.Hour = 12; timeToken.HourPeriod = HourPeriod.Am; } else if (timeToken.Hour < 12) { timeToken.HourPeriod = HourPeriod.Am; } else if (timeToken.Hour == 12) { timeToken.HourPeriod = HourPeriod.Pm; } else { timeToken.Hour -= 12; timeToken.HourPeriod = HourPeriod.Pm; } } else { if (timeToken.Hour < 8) { timeToken.HourPeriod = HourPeriod.Pm; } else if (timeToken.Hour < 12) { timeToken.HourPeriod = HourPeriod.Am; } else if (timeToken.Hour == 12) { timeToken.HourPeriod = HourPeriod.Pm; } else { timeToken.Hour -= 12; timeToken.HourPeriod = HourPeriod.Pm; } } return(timeToken); }
/// <summary> /// Parses a <see cref="Match"/> into a <see cref="TimeToken"/>. /// </summary> /// <param name="match">A <see cref="Match"/> representation of a <see cref="TimeToken"/>.</param> /// <param name="provider">An <see cref="IFormatProvider"/>.</param> /// <returns>The <see cref="TimeToken"/> 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="TimeToken"/>.</exception> protected override TimeToken ParseInternal(Match match, IFormatProvider provider) { NormalTimeToken timeToken = new NormalTimeToken(); provider = Resources.ResourceManager.GetEffectiveProvider(provider); // Parse hour if (match.Groups["hour"].Success) { timeToken.Hour = int.Parse(match.Groups["hour"].Value, provider); } // Parse minute if (match.Groups["minute"].Success) { timeToken.Minute = int.Parse(match.Groups["minute"].Value, provider); } // Parse second if (match.Groups["second"].Success) { timeToken.Second = int.Parse(match.Groups["second"].Value, provider); } // Parse hour period if (match.Groups["am"].Success) { timeToken.HourPeriod = HourPeriod.Am; } else if (match.Groups["pm"].Success) { timeToken.HourPeriod = HourPeriod.Pm; } else if (match.Groups["military"].Success) { if (timeToken.Hour == 0) { timeToken.Hour = 12; timeToken.HourPeriod = HourPeriod.Am; } else if (timeToken.Hour < 12) { timeToken.HourPeriod = HourPeriod.Am; } else if (timeToken.Hour == 12) { timeToken.HourPeriod = HourPeriod.Pm; } else { timeToken.Hour -= 12; timeToken.HourPeriod = HourPeriod.Pm; } } else { if (timeToken.Hour < 8) { timeToken.HourPeriod = HourPeriod.Pm; } else if (timeToken.Hour < 12) { timeToken.HourPeriod = HourPeriod.Am; } else if (timeToken.Hour == 12) { timeToken.HourPeriod = HourPeriod.Pm; } else { timeToken.Hour -= 12; timeToken.HourPeriod = HourPeriod.Pm; } } return timeToken; }