Annotation 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 Classes
    Modifier and Type
    Class
    Description
    static @interface 
    Defines several @DateRange annotations on the same element.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Class<?>[]
     
    Period or Duration for the upper limit of now + max
     
    Period or Duration for the lower limit of now + min (often a negative period)
  • Element Details

    • min

      String min
      Period or Duration for the lower limit of now + min (often a negative period)
      Default:
      ""
    • max

      String max
      Period or Duration for the upper limit of now + max
      Default:
      ""
    • message

      String message
      Default:
      "{avaje.DateRange.message}"
    • groups

      Class<?>[] groups
      Default:
      {}