Skip to main content
A configuration of Validity has two things: the messages of the violations, and the clock that says what “now” is. Every validation uses one.

Once, at startup

Validity.configure { } replaces the default configuration, the one every validation uses unless it is given another:
Each call starts from the built-in defaults, so a second call undoes the first. Call it once, before the first validation.

For one call

Validity { } creates a configuration that starts from the default one and changes only what its block says. Pass it to validate: the default configuration does not change, so other requests keep theirs.
The codes stay the same in every language, which is what lets programs ignore the messages. Every entry takes one: validate(validity), validateBlocking(validity), the OrThrow versions, and, for a ContextualValidatable, validate(context, validity). The configuration reaches the nested objects and elements too.

Common uses

Build one Validity per language at startup, and pick it from the Accept-Language of the request:
Rules about time read the clock of the configuration, so a test can fix “now” for one call without touching the default:
“Today” depends on the zone. Give the call the clock of the user’s zone:
Validity { } builds its configuration when it is created, on top of the default of that moment. Create the ones you reuse, such as one per language, after Validity.configure, and keep them in a value.