/// <summary> /// Returns a set of regular expressions supported by this parser. /// </summary> /// <param name="provider">An <see cref="IFormatProvider"/>.</param> /// <returns>A set of regular expressions supported by this parser.</returns> public override IEnumerable <string> GetPatterns(IFormatProvider provider) { if (provider.IsMonthFirst()) { return(GetPatternsWithMonthFirst(provider)); } else if (provider.IsYearFirst()) { return(GetPatternsWithYearFirst(provider)); } else { return(GetPatternsWithDayFirst(provider)); } }
/// <summary> /// Returns a set of regular expressions supported by this parser. /// </summary> /// <param name="provider">An <see cref="IFormatProvider"/>.</param> /// <returns>A set of regular expressions supported by this parser.</returns> public override IEnumerable<string> GetPatterns(IFormatProvider provider) { if (provider.IsMonthFirst()) { return GetPatternsWithMonthFirst(provider); } else if (provider.IsYearFirst()) { return GetPatternsWithYearFirst(provider); } else { return GetPatternsWithDayFirst(provider); } }
/// <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(); // Day only if (this.Day.HasValue && !this.Month.HasValue && !this.Year.HasValue) { return(string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), Resources.ResourceManager.GetString("NormalDateTokenDayOnlyFormatString", provider), DateTimeExtensions.GetOrdinalDayString(this.Day.Value, provider))); } // Day and month if (this.Day.HasValue && this.Month.HasValue && !this.Year.HasValue) { string formatString = provider.IsMonthFirst() ? Resources.ResourceManager.GetString("NormalDateTokenMonthAndDayFormatString", provider) : Resources.ResourceManager.GetString("NormalDateTokenDayAndMonthFormatString", provider); return(string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), formatString, this.Day.Value, DateTimeExtensions.GetMonthString(this.Month.Value, provider))); } // Day, month, and year if (this.Day.HasValue && this.Month.HasValue && this.Year.HasValue) { string formatString = provider.IsMonthFirst() ? Resources.ResourceManager.GetString("NormalDateTokenMonthDayAndYearFormatString", provider) : Resources.ResourceManager.GetString("NormalDateTokenDayMonthAndYearFormatString", provider); return(string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), formatString, this.Day.Value, DateTimeExtensions.GetMonthString(this.Month.Value, provider), this.Year.Value)); } // Month only if (!this.Day.HasValue && this.Month.HasValue && !this.Year.HasValue) { return(string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), Resources.ResourceManager.GetString("NormalDateTokenMonthOnlyFormatString", provider), DateTimeExtensions.GetMonthString(this.Month.Value, provider))); } // Month and year if (!this.Day.HasValue && this.Month.HasValue && this.Year.HasValue) { return(string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), Resources.ResourceManager.GetString("NormalDateTokenMonthAndYearFormatString", provider), DateTimeExtensions.GetMonthString(this.Month.Value, provider), this.Year)); } // Year if (!this.Day.HasValue && !this.Month.HasValue && this.Year.HasValue) { return(string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), Resources.ResourceManager.GetString("NormalDateTokenYearOnlyFormatString", provider), this.Year)); } // Unsupported return(this.GetType().ToString()); } catch { return(this.GetType().ToString()); } }
/// <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(); // Day only if (this.Day.HasValue && !this.Month.HasValue && !this.Year.HasValue) { return string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), Resources.ResourceManager.GetString("NormalDateTokenDayOnlyFormatString", provider), DateTimeExtensions.GetOrdinalDayString(this.Day.Value, provider)); } // Day and month if (this.Day.HasValue && this.Month.HasValue && !this.Year.HasValue) { string formatString = provider.IsMonthFirst() ? Resources.ResourceManager.GetString("NormalDateTokenMonthAndDayFormatString", provider) : Resources.ResourceManager.GetString("NormalDateTokenDayAndMonthFormatString", provider); return string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), formatString, this.Day.Value, DateTimeExtensions.GetMonthString(this.Month.Value, provider)); } // Day, month, and year if (this.Day.HasValue && this.Month.HasValue && this.Year.HasValue) { string formatString = provider.IsMonthFirst() ? Resources.ResourceManager.GetString("NormalDateTokenMonthDayAndYearFormatString", provider) : Resources.ResourceManager.GetString("NormalDateTokenDayMonthAndYearFormatString", provider); return string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), formatString, this.Day.Value, DateTimeExtensions.GetMonthString(this.Month.Value, provider), this.Year.Value); } // Month only if (!this.Day.HasValue && this.Month.HasValue && !this.Year.HasValue) { return string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), Resources.ResourceManager.GetString("NormalDateTokenMonthOnlyFormatString", provider), DateTimeExtensions.GetMonthString(this.Month.Value, provider)); } // Month and year if (!this.Day.HasValue && this.Month.HasValue && this.Year.HasValue) { return string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), Resources.ResourceManager.GetString("NormalDateTokenMonthAndYearFormatString", provider), DateTimeExtensions.GetMonthString(this.Month.Value, provider), this.Year); } // Year if (!this.Day.HasValue && !this.Month.HasValue && this.Year.HasValue) { return string.Format( Resources.ResourceManager.GetEffectiveProvider(provider), Resources.ResourceManager.GetString("NormalDateTokenYearOnlyFormatString", provider), this.Year); } // Unsupported return this.GetType().ToString(); } catch { return this.GetType().ToString(); } }