| | | 1 | | // ReSharper disable once CheckNamespace |
| | | 2 | | namespace FluentValidation; |
| | | 3 | | |
| | | 4 | | /// <summary>Rules for <see cref="DateTime"/> values. "Today" rules compare the calendar day with <see cref="DateTime.To |
| | | 5 | | public static class FluentValidationDateTimeHelpers |
| | | 6 | | { |
| | | 7 | | /// <summary>The value must be after <paramref name="comparer"/>.</summary> |
| | | 8 | | /// <typeparam name="T">The validated type.</typeparam> |
| | | 9 | | /// <param name="ruleBuilder">The rule builder.</param> |
| | | 10 | | /// <param name="comparer">The value to compare with.</param> |
| | | 11 | | /// <returns>The rule builder options.</returns> |
| | 3 | 12 | | public static IRuleBuilderOptions<T, DateTime> GreaterThan< T >( this IRuleBuilder<T, DateTime> ruleBuilder, DateTim |
| | | 13 | | |
| | | 14 | | /// <summary>The value must be on or after <paramref name="comparer"/>.</summary> |
| | | 15 | | /// <typeparam name="T">The validated type.</typeparam> |
| | | 16 | | /// <param name="ruleBuilder">The rule builder.</param> |
| | | 17 | | /// <param name="comparer">The value to compare with.</param> |
| | | 18 | | /// <returns>The rule builder options.</returns> |
| | | 19 | | public static IRuleBuilderOptions<T, DateTime> GreaterThanOrEqualTo< T >( this IRuleBuilder<T, DateTime> ruleBuilder |
| | 3 | 20 | | => ruleBuilder.Must( value => value >= comparer ).WithErrorCode( nameof( GreaterThanOrEqualTo ) ); |
| | | 21 | | |
| | | 22 | | /// <summary>The value must be today (any time) or later.</summary> |
| | | 23 | | /// <typeparam name="T">The validated type.</typeparam> |
| | | 24 | | /// <param name="ruleBuilder">The rule builder.</param> |
| | | 25 | | /// <returns>The rule builder options.</returns> |
| | 12 | 26 | | public static IRuleBuilderOptions<T, DateTime> GreaterThanOrEqualToToday< T >( this IRuleBuilder<T, DateTime> ruleBu |
| | | 27 | | |
| | | 28 | | /// <summary>The value must be tomorrow or later.</summary> |
| | | 29 | | /// <typeparam name="T">The validated type.</typeparam> |
| | | 30 | | /// <param name="ruleBuilder">The rule builder.</param> |
| | | 31 | | /// <returns>The rule builder options.</returns> |
| | 9 | 32 | | public static IRuleBuilderOptions<T, DateTime> GreaterThanToday< T >( this IRuleBuilder<T, DateTime> ruleBuilder ) = |
| | | 33 | | |
| | | 34 | | /// <summary>The value must be before <paramref name="comparer"/>.</summary> |
| | | 35 | | /// <typeparam name="T">The validated type.</typeparam> |
| | | 36 | | /// <param name="ruleBuilder">The rule builder.</param> |
| | | 37 | | /// <param name="comparer">The value to compare with.</param> |
| | | 38 | | /// <returns>The rule builder options.</returns> |
| | 3 | 39 | | public static IRuleBuilderOptions<T, DateTime> LessThan< T >( this IRuleBuilder<T, DateTime> ruleBuilder, DateTime c |
| | | 40 | | |
| | | 41 | | /// <summary>The value must be on or before <paramref name="comparer"/>.</summary> |
| | | 42 | | /// <typeparam name="T">The validated type.</typeparam> |
| | | 43 | | /// <param name="ruleBuilder">The rule builder.</param> |
| | | 44 | | /// <param name="comparer">The value to compare with.</param> |
| | | 45 | | /// <returns>The rule builder options.</returns> |
| | | 46 | | public static IRuleBuilderOptions<T, DateTime> LessThanOrEqualTo< T >( this IRuleBuilder<T, DateTime> ruleBuilder, D |
| | 3 | 47 | | => ruleBuilder.Must( value => value <= comparer ).WithErrorCode( nameof( LessThanOrEqualTo ) ); |
| | | 48 | | |
| | | 49 | | /// <summary>The value must be today (any time) or earlier.</summary> |
| | | 50 | | /// <typeparam name="T">The validated type.</typeparam> |
| | | 51 | | /// <param name="ruleBuilder">The rule builder.</param> |
| | | 52 | | /// <returns>The rule builder options.</returns> |
| | 9 | 53 | | public static IRuleBuilderOptions<T, DateTime> LessThanOrEqualToToday< T >( this IRuleBuilder<T, DateTime> ruleBuild |
| | | 54 | | |
| | | 55 | | /// <summary>The value must be yesterday or earlier.</summary> |
| | | 56 | | /// <typeparam name="T">The validated type.</typeparam> |
| | | 57 | | /// <param name="ruleBuilder">The rule builder.</param> |
| | | 58 | | /// <returns>The rule builder options.</returns> |
| | 9 | 59 | | public static IRuleBuilderOptions<T, DateTime> LessThanToday< T >( this IRuleBuilder<T, DateTime> ruleBuilder ) => r |
| | | 60 | | |
| | | 61 | | /// <summary>The value must be empty, or today (any time) or later.</summary> |
| | | 62 | | /// <typeparam name="T">The validated type.</typeparam> |
| | | 63 | | /// <param name="ruleBuilder">The rule builder.</param> |
| | | 64 | | /// <returns>The rule builder options.</returns> |
| | | 65 | | public static IRuleBuilderOptions<T, DateTime?> NullableGreaterThanOrEqualToToday< T >( this IRuleBuilder<T, DateTim |
| | 6 | 66 | | => ruleBuilder.Must( value => value is null || value.Value.Date >= DateTime.Today ).WithErrorCode( nameof( Nulla |
| | | 67 | | } |