/// <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) { SpecialDateDefinition specialDateDefinition = GetSpecialDateDefinitionForMatch(match); if (specialDateDefinition == null) { throw new FormatException(); } return(new SpecialDateToken { SpecialDate = specialDateDefinition.SpecialDate }); }
/// <summary> /// Returns a string that represents the current object. /// </summary> /// <param name="provider">An <see cref="IFormatProvider"/> to use.</param> /// <returns>A string that represents the current object.</returns> public override string ToString(IFormatProvider provider) { try { this.ThrowIfNotValid(); SpecialDateDefinition specialDateDefinition = this.GetSpecialDateDefinition(); return(specialDateDefinition.GetName(provider)); } catch { return(this.GetType().ToString()); } }
/// <summary> /// Returns the next date after <paramref name="minDate"/> that is represented by this token. /// </summary> /// <remarks> /// This method may return a date that is before <paramref name="minDate"/> if there is no date after <paramref /// name="minDate"/> that is represented by this token. /// </remarks> /// <param name="minDate">The minimum date to return. The time part is ignored.</param> /// <param name="inclusive">A value indicating whether the returned date should be on or after rather than /// strictly after <paramref name="minDate"/>.</param> /// <returns>The next date after <paramref name="minDate"/> that is represented by this token.</returns> /// <exception cref="InvalidOperationException">If this token is not valid.</exception> public override DateTime ToDateTime(DateTime minDate, bool inclusive) { this.ThrowIfNotValid(); SpecialDateDefinition specialDateDefinition = this.GetSpecialDateDefinition(); DateTime date = new DateTime( minDate.Year, specialDateDefinition.Month, specialDateDefinition.Day); if (date < minDate.Date || (date == minDate.Date && !inclusive)) { date = date.AddYears(1); } return(date); }