Skip to content

Commit 38084a8

Browse files
remove the verb 'is' from dateTime validators
1 parent a592233 commit 38084a8

File tree

6 files changed

+53
-53
lines changed

6 files changed

+53
-53
lines changed

example/lib/forms_with_validate_granularlly.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class _BodyState extends State<_Body> {
100100
hintText: 'YYYY-MM-DD',
101101
prefixIcon: Icon(Icons.calendar_today),
102102
),
103-
validator: V.required(V.dateTime(V.isBefore(DateTime.now(),
104-
isBeforeMsg: (_, __) => 'Date must be in the past.'))),
103+
validator: V.required(V.dateTime(V.before(DateTime.now(),
104+
beforeMsg: (_, __) => 'Date must be in the past.'))),
105105
keyboardType: TextInputType.datetime,
106106
textInputAction: TextInputAction.next,
107107
onTap: () async {

lib/src/form_builder_validators.dart

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,14 +3322,14 @@ final class Validators {
33223322
val.betweenLength(min, max, betweenLengthMsg: betweenLengthMsg);
33233323

33243324
// DateTime Validators
3325-
/// {@template validator_is_after}
3325+
/// {@template validator_after}
33263326
/// Creates a [DateTime] validator that checks if an input date occurs after
33273327
/// `reference`.
33283328
///
33293329
/// ## Parameters
33303330
/// - `reference` (`DateTime`): The baseline date against which the input will be compared.
33313331
/// This serves as the minimum acceptable date (exclusive by default).
3332-
/// - `isAfterMsg` (`String Function(DateTime input, DateTime reference)?`): Optional custom
3332+
/// - `afterMsg` (`String Function(DateTime input, DateTime reference)?`): Optional custom
33333333
/// error message generator. When provided, it receives both the input and reference
33343334
/// dates to construct a context-aware error message.
33353335
/// - `inclusive` (`bool`): When set to `true`, allows the input date to exactly match
@@ -3343,36 +3343,36 @@ final class Validators {
33433343
/// ## Examples
33443344
/// ```dart
33453345
/// // Basic usage requiring date after January 1st, 2025
3346-
/// final validator = isAfter(DateTime(2025));
3346+
/// final validator = Validators.after(DateTime(2025));
33473347
///
33483348
/// // Inclusive validation allowing exact match
3349-
/// final inclusiveValidator = isAfter(
3349+
/// final inclusiveValidator = Validators.after(
33503350
/// DateTime(2024),
33513351
/// inclusive: true,
33523352
/// );
33533353
///
33543354
/// // Custom error message
3355-
/// final customValidator = isAfter(
3355+
/// final customValidator = Validators.after(
33563356
/// DateTime(2024),
33573357
/// isAfterMsg: (_, ref) => 'Please select a date after ${ref.toString()}',
33583358
/// );
33593359
/// ```
33603360
/// {@endtemplate}
3361-
static Validator<DateTime> isAfter(
3361+
static Validator<DateTime> after(
33623362
DateTime reference, {
3363-
String Function(DateTime input, DateTime reference)? isAfterMsg,
3363+
String Function(DateTime input, DateTime reference)? afterMsg,
33643364
c.bool inclusive = false,
33653365
}) =>
3366-
val.isAfter(reference, isAfterMsg: isAfterMsg, inclusive: inclusive);
3366+
val.after(reference, afterMsg: afterMsg, inclusive: inclusive);
33673367

3368-
/// {@template validator_is_before}
3368+
/// {@template validator_before}
33693369
/// Creates a [DateTime] validator that checks if an input date occurs before
33703370
/// `reference`.
33713371
///
33723372
/// ## Parameters
33733373
/// - `reference` (`DateTime`): The baseline date against which the input will be compared.
33743374
/// This serves as the maximum acceptable date (exclusive by default).
3375-
/// - `isBeforeMsg` (`String Function(DateTime input, DateTime reference)?`): Optional custom
3375+
/// - `beforeMsg` (`String Function(DateTime input, DateTime reference)?`): Optional custom
33763376
/// error message generator. When provided, it receives both the input and reference
33773377
/// dates to construct a context-aware error message.
33783378
/// - `inclusive` (`bool`): When set to `true`, allows the input date to exactly match
@@ -3387,29 +3387,29 @@ final class Validators {
33873387
/// ## Examples
33883388
/// ```dart
33893389
/// // Basic usage requiring date before January 1st, 2025
3390-
/// final validator = isBefore(DateTime(2025));
3390+
/// final validator = Validators.before(DateTime(2025));
33913391
///
33923392
/// // Inclusive validation allowing exact match
3393-
/// final inclusiveValidator = isBefore(
3393+
/// final inclusiveValidator = Validators.before(
33943394
/// DateTime(2024),
33953395
/// inclusive: true,
33963396
/// );
33973397
///
33983398
/// // Custom error message
3399-
/// final customValidator = isBefore(
3399+
/// final customValidator = Validators.before(
34003400
/// DateTime(2024),
34013401
/// isBeforeMsg: (_, ref) => 'Please select a date before ${ref.toString()}',
34023402
/// );
34033403
/// ```
34043404
/// {@endtemplate}
3405-
static Validator<DateTime> isBefore(
3405+
static Validator<DateTime> before(
34063406
DateTime reference, {
3407-
String Function(DateTime input, DateTime reference)? isBeforeMsg,
3407+
String Function(DateTime input, DateTime reference)? beforeMsg,
34083408
c.bool inclusive = false,
34093409
}) =>
3410-
val.isBefore(reference, isBeforeMsg: isBeforeMsg, inclusive: inclusive);
3410+
val.before(reference, beforeMsg: beforeMsg, inclusive: inclusive);
34113411

3412-
/// {@template validator_is_date_time_between}
3412+
/// {@template validator_date_time_between}
34133413
/// Creates a [DateTime] validator that checks if an input date falls within a specified
34143414
/// range defined by `minReference` and `maxReference`.
34153415
///
@@ -3422,7 +3422,7 @@ final class Validators {
34223422
/// Input dates must occur after this date (or equal to it if `minInclusive` is true).
34233423
/// - `maxReference` (`DateTime`): The upper bound of the acceptable date range.
34243424
/// Input dates must occur before this date (or equal to it if `maxInclusive` is true).
3425-
/// - `isDateTimeBetweenMsg` (`String Function(DateTime, DateTime, DateTime)?`): Optional
3425+
/// - `dateTimeBetweenMsg` (`String Function(DateTime, DateTime, DateTime)?`): Optional
34263426
/// custom error message generator. When provided, it receives the input date and both
34273427
/// reference dates to construct a context-aware error message.
34283428
/// - `minInclusive` (`bool`): When set to `true`, allows the input date to exactly match
@@ -3443,39 +3443,39 @@ final class Validators {
34433443
/// ## Examples
34443444
/// ```dart
34453445
/// // Basic usage requiring date between 2023 and 2025
3446-
/// final validator = isDateTimeBetween(
3446+
/// final validator = Validators.dateTimeBetween(
34473447
/// DateTime(2023),
34483448
/// DateTime(2025),
34493449
/// );
34503450
///
34513451
/// // Inclusive validation allowing exact matches
3452-
/// final inclusiveValidator = isDateTimeBetween(
3452+
/// final inclusiveValidator = Validators.dateTimeBetween(
34533453
/// DateTime(2023),
34543454
/// DateTime(2025),
34553455
/// minInclusive: true,
34563456
/// maxInclusive: true,
34573457
/// );
34583458
///
34593459
/// // Custom error message
3460-
/// final customValidator = isDateTimeBetween(
3460+
/// final customValidator = Validators.dateTimeBetween(
34613461
/// DateTime(2023),
34623462
/// DateTime(2025),
34633463
/// isDateTimeBetweenMsg: (_, min, max) =>
34643464
/// 'Please select a date between ${min.toString()} and ${max.toString()}',
34653465
/// );
34663466
/// ```
34673467
/// {@endtemplate}
3468-
static Validator<DateTime> isDateTimeBetween(
3468+
static Validator<DateTime> dateTimeBetween(
34693469
DateTime minReference,
34703470
DateTime maxReference, {
34713471
String Function(
34723472
DateTime input, DateTime minReference, DateTime maxReference)?
3473-
isDateTimeBetweenMsg,
3473+
dateTimeBetweenMsg,
34743474
c.bool leftInclusive = false,
34753475
c.bool rightInclusive = false,
34763476
}) =>
3477-
val.isDateTimeBetween(minReference, maxReference,
3478-
isDateTimeBetweenMsg: isDateTimeBetweenMsg,
3477+
val.dateTimeBetween(minReference, maxReference,
3478+
dateTimeBetweenMsg: dateTimeBetweenMsg,
34793479
minInclusive: leftInclusive,
34803480
maxInclusive: rightInclusive);
34813481

lib/src/validators/datetime_validators.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
import '../../localization/l10n.dart';
22
import 'constants.dart';
33

4-
/// {@macro validator_is_after}
5-
Validator<DateTime> isAfter(
4+
/// {@macro validator_after}
5+
Validator<DateTime> after(
66
DateTime reference, {
7-
String Function(DateTime input, DateTime reference)? isAfterMsg,
7+
String Function(DateTime input, DateTime reference)? afterMsg,
88
bool inclusive = false,
99
}) {
1010
return (DateTime input) {
1111
return input.isAfter(reference) ||
1212
(inclusive ? input.isAtSameMomentAs(reference) : false)
1313
? null
14-
: isAfterMsg?.call(input, reference) ??
14+
: afterMsg?.call(input, reference) ??
1515
FormBuilderLocalizations.current
1616
.dateMustBeAfterErrorText(reference.toLocal());
1717
};
1818
}
1919

20-
/// {@macro validator_is_before}
21-
Validator<DateTime> isBefore(
20+
/// {@macro validator_before}
21+
Validator<DateTime> before(
2222
DateTime reference, {
23-
String Function(DateTime input, DateTime reference)? isBeforeMsg,
23+
String Function(DateTime input, DateTime reference)? beforeMsg,
2424
bool inclusive = false,
2525
}) {
2626
return (DateTime input) {
2727
return input.isBefore(reference) ||
2828
(inclusive ? input.isAtSameMomentAs(reference) : false)
2929
? null
30-
: isBeforeMsg?.call(input, reference) ??
30+
: beforeMsg?.call(input, reference) ??
3131
FormBuilderLocalizations.current
3232
.dateMustBeBeforeErrorText(reference.toLocal());
3333
};
3434
}
3535

36-
/// {@macro validator_is_date_time_between}
37-
Validator<DateTime> isDateTimeBetween(
36+
/// {@macro validator_date_time_between}
37+
Validator<DateTime> dateTimeBetween(
3838
DateTime minReference,
3939
DateTime maxReference, {
4040
String Function(DateTime input, DateTime minReference, DateTime maxReference)?
41-
isDateTimeBetweenMsg,
41+
dateTimeBetweenMsg,
4242
bool minInclusive = false,
4343
bool maxInclusive = false,
4444
}) {
@@ -52,7 +52,7 @@ Validator<DateTime> isDateTimeBetween(
5252
(input.isAfter(minReference) ||
5353
(minInclusive ? input.isAtSameMomentAs(minReference) : false))
5454
? null
55-
: isDateTimeBetweenMsg?.call(input, minReference, maxReference) ??
55+
: dateTimeBetweenMsg?.call(input, minReference, maxReference) ??
5656
FormBuilderLocalizations.current.dateMustBeBetweenErrorText(
5757
minReference.toLocal(), maxReference.toLocal());
5858
};

test/src/validators/datetime_validators/is_after_validator_test.dart renamed to test/src/validators/datetime_validators/after_validator_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void main() {
77
setUpAll(() async {
88
await initializeDateFormatting('en', null);
99
});
10-
group('Validator: isAfter', () {
10+
group('Validator: after', () {
1111
test('Validation for the year 1994', () {
1212
final DateTime reference = DateTime(1994);
1313
final DateTime eq = reference.copyWith();
@@ -16,7 +16,7 @@ void main() {
1616
final DateTime before1Year = DateTime(1993);
1717
final DateTime before1Sec =
1818
reference.subtract(const Duration(seconds: 1));
19-
final Validator<DateTime> v = isAfter(reference);
19+
final Validator<DateTime> v = after(reference);
2020
final String errorMsg =
2121
FormBuilderLocalizations.current.dateMustBeAfterErrorText(reference);
2222

@@ -56,7 +56,7 @@ void main() {
5656
final DateTime before1Year = reference.copyWith(year: 2088);
5757
final DateTime before1Sec =
5858
reference.subtract(const Duration(seconds: 1));
59-
final Validator<DateTime> v = isAfter(reference, inclusive: true);
59+
final Validator<DateTime> v = after(reference, inclusive: true);
6060
final String errorMsg =
6161
FormBuilderLocalizations.current.dateMustBeAfterErrorText(reference);
6262

@@ -93,7 +93,7 @@ void main() {
9393
const String errorMsg = 'error msg';
9494
final DateTime reference = DateTime(2);
9595
final Validator<DateTime> v =
96-
isAfter(reference, isAfterMsg: (_, __) => errorMsg);
96+
after(reference, afterMsg: (_, __) => errorMsg);
9797

9898
expect(
9999
v(reference.copyWith()),

test/src/validators/datetime_validators/is_before_validator_test.dart renamed to test/src/validators/datetime_validators/before_validator_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void main() {
77
setUpAll(() async {
88
await initializeDateFormatting('en', null);
99
});
10-
group('Validator: isBefore', () {
10+
group('Validator: before', () {
1111
test('Validation for the year 1994', () {
1212
final DateTime reference = DateTime(1994);
1313
final DateTime eq = reference.copyWith();
@@ -16,7 +16,7 @@ void main() {
1616
final DateTime before1Year = DateTime(1993);
1717
final DateTime before1Sec =
1818
reference.subtract(const Duration(seconds: 1));
19-
final Validator<DateTime> v = isBefore(reference);
19+
final Validator<DateTime> v = before(reference);
2020
final String errorMsg =
2121
FormBuilderLocalizations.current.dateMustBeBeforeErrorText(reference);
2222

@@ -56,7 +56,7 @@ void main() {
5656
final DateTime before1Year = reference.copyWith(year: 2088);
5757
final DateTime before1Sec =
5858
reference.subtract(const Duration(seconds: 1));
59-
final Validator<DateTime> v = isBefore(reference, inclusive: true);
59+
final Validator<DateTime> v = before(reference, inclusive: true);
6060
final String errorMsg =
6161
FormBuilderLocalizations.current.dateMustBeBeforeErrorText(reference);
6262

@@ -93,7 +93,7 @@ void main() {
9393
const String errorMsg = 'error msg';
9494
final DateTime reference = DateTime(2);
9595
final Validator<DateTime> v =
96-
isBefore(reference, isBeforeMsg: (_, __) => errorMsg);
96+
before(reference, beforeMsg: (_, __) => errorMsg);
9797

9898
expect(
9999
v(reference.copyWith()),

test/src/validators/datetime_validators/is_datetime_between_validator_test.dart renamed to test/src/validators/datetime_validators/datetime_between_validator_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void main() {
77
setUpAll(() async {
88
await initializeDateFormatting('en', null);
99
});
10-
group('Validator: isDateTimeBetween', () {
10+
group('Validator: dateTimeBetween', () {
1111
test('Validation for the range 1994 and 1997', () {
1212
final DateTime leftReference = DateTime(1994);
1313
final DateTime rightReference = DateTime(1997);
@@ -25,7 +25,7 @@ void main() {
2525
final DateTime beforeLeft1Micro =
2626
leftReference.subtract(const Duration(microseconds: 1));
2727
final Validator<DateTime> v =
28-
isDateTimeBetween(leftReference, rightReference);
28+
dateTimeBetween(leftReference, rightReference);
2929
final String errorMsg = FormBuilderLocalizations.current
3030
.dateMustBeBetweenErrorText(leftReference, rightReference);
3131

@@ -91,7 +91,7 @@ void main() {
9191
final DateTime before1Sec =
9292
leftReference.subtract(const Duration(seconds: 1));
9393
final Validator<DateTime> v =
94-
isDateTimeBetween(leftReference, rightReference, minInclusive: true);
94+
dateTimeBetween(leftReference, rightReference, minInclusive: true);
9595
final String errorMsg = FormBuilderLocalizations.current
9696
.dateMustBeBetweenErrorText(leftReference, rightReference);
9797

@@ -145,9 +145,9 @@ void main() {
145145
const String errorMsg = 'error msg';
146146
final DateTime leftReference = DateTime(2);
147147
final DateTime rightReference = DateTime(5);
148-
final Validator<DateTime> v = isDateTimeBetween(
148+
final Validator<DateTime> v = dateTimeBetween(
149149
leftReference, rightReference,
150-
isDateTimeBetweenMsg: (_, __, ___) => errorMsg);
150+
dateTimeBetweenMsg: (_, __, ___) => errorMsg);
151151

152152
expect(
153153
v(rightReference.copyWith()),
@@ -173,7 +173,7 @@ void main() {
173173
'Should throw AssertionError when the right reference is not after left reference',
174174
() {
175175
expect(
176-
() => isDateTimeBetween(
176+
() => dateTimeBetween(
177177
DateTime(1990, 12, 23, 20), DateTime(1990, 12, 22, 20)),
178178
throwsAssertionError);
179179
});

0 commit comments

Comments
 (0)