isBeforeOrEqualTo

fun Validatable<Instant?>.isBeforeOrEqualTo(other: Instant): Constraint

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")

fun Validatable<LocalDate?>.isBeforeOrEqualTo(other: LocalDate): Constraint

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")

fun Validatable<LocalTime?>.isBeforeOrEqualTo(other: LocalTime): Constraint

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")

fun Validatable<LocalDateTime?>.isBeforeOrEqualTo(other: LocalDateTime): Constraint

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")