ClockProvider class abstract interface

Where the date constraints (@Past(), @FutureDate(), ...) get the current time.

The validator uses DefaultClockProvider, the system clock. Give a BeanValidator another one to make date checks repeatable in tests, or to use a server-wide clock. Jakarta's ClockProvider; it returns the time itself, since Dart has no Clock type.

// Tests run on a fixed date.
final class FixedClock implements ClockProvider {
  const FixedClock(this.time);
  final DateTime time;
  @override
  DateTime now() => time;
}

BeanValidator(clockProvider: FixedClock(DateTime.utc(2026, 1, 1)));

Spring (Java):

LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.setClockProvider(() -> Clock.fixed(instant, ZoneOffset.UTC));

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
now() → DateTime
The current time, read once per date constraint check.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited