Package io.avaje.validation.constraints
Annotation Interface DateRange
@Documented
@Retention(RUNTIME)
@Repeatable(List.class)
@Target({METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER,TYPE_USE})
public @interface DateRange
The annotated element has to be in the appropriate date or temporal range.
Can be applied to java time types LocalDate, LocalTime, LocalDateTime, Instant, OffsetDateTime, OffsetTime, ZonedDateTime, Year, YearMonth.
The Period can be defined as a valid Period or Duration.
Example Periods
"P1Y2M3D" as 1 year, 2 months, 3 days "P4W" as 4 weeks "P5D" as 5 days "-P5D" as minus 5 days
Example Durations
"PT10H" as 10 hours "-PT6H30M" as minus (6 hours and 30 minutes)" "P2DT3H4M" as 2 days, 3 hours and 4 minutes
Use of 'now'
'now' can be used for a min or max. When used with date + time types Instance, LocalDateTime, OffsetDateTime, and ZonedDateTime then the configured temporal tolerance is used.
Refer to Validator.Builder#temporalTolerance(Duration)
Examples
// between 120yrs and 3yrs old
@DateRange(min="-P120Y", max = "-P3Y")
LocalDate dateOfBirth;
// between (now - tolerance) and 3 months into the future
@DateRange(min="now, max = "P3M")
OffsetDateTime expectedDelivery;
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceDefines several@DateRangeannotations on the same element. -
Optional Element Summary
Optional Elements