isBeforeOrEqualTo
The validatable Instant must be before or equal to other when this constraint is applied.
Use isInPastOrIsPresent to compare against the system clock Clock.System
.
Code example:
val now = Instant.parse("2024-08-31T12:30:15Z")
val validate = Validator<Instant> { isBeforeOrEqualTo(now) }
validate(now - 5.seconds) // Success
validate(now) // Success
validate(now + 5.seconds) // Failure (message: Must be before or equal to "2024-08-31T12:30:15Z")
Content copied to clipboard
The validatable LocalDate must be before or equal to other when this constraint is applied.
Use isInPastOrIsPresent to compare against the system clock Clock.System
.
Code example:
val now = LocalDate.parse("2024-08-31")
val validate = Validator<LocalDate> { isBeforeOrEqualTo(now) }
validate(now.minus(2, DateTimeUnit.DAY)) // Success
validate(now) // Success
validate(now.plus(2, DateTimeUnit.DAY)) // Failure (message: Must be before or equal to "2024-08-31")
Content copied to clipboard
The validatable LocalTime must be before or equal to other when this constraint is applied.
Use isInPastOrIsPresent to compare against the system clock Clock.System
.
Code example:
val now = LocalTime.parse("12:30:15")
val validate = Validator<LocalTime> { isBeforeOrEqualTo(now) }
validate(LocalTime.fromSecondOfDay(now.toSecondOfDay() - 5)) // Success
validate(now) // Success
validate(LocalTime.fromSecondOfDay(now.toSecondOfDay() + 5)) // Failure (message: Must be before or equal to "12:30:15")
Content copied to clipboard
The validatable LocalDateTime must be before or equal to other when this constraint is applied.
Use isInPastOrIsPresent to compare against the system clock Clock.System
.
Code example:
val now = LocalDateTime.parse("2024-08-31T12:30:15")
val timezone = TimeZone.currentSystemDefault()
val validate = Validator<LocalDateTime> { isBeforeOrEqualTo(now) }
validate((now.toInstant(timezone) - 5.seconds).toLocalDateTime(timezone)) // Success
validate(now) // Success
validate((now.toInstant(timezone) + 5.seconds).toLocalDateTime(timezone)) // Failure (message: Must be before or equal to "2024-08-31T12:30:15")
Content copied to clipboard