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