isInPast

@JvmName(name = "instantIsInPast")
fun Validatable<Instant?>.isInPast(): Constraint

The validatable Instant must be in the past when this constraint is applied.

The comparison is made against the system clock Clock.System. Use isBefore to compare against an arbitrary Instant.

Code example:

val validate = Validator<Instant> { isInPast() }
val now = Clock.System.now()
validate(now - 5.seconds) // Success
validate(now + 5.seconds) // Failure (message: Must be in the past)

@JvmName(name = "localDateIsInPast")
fun Validatable<LocalDate?>.isInPast(): Constraint

The validatable LocalDate must be in the past when this constraint is applied.

The comparison is made against the system clock Clock.System and time zone TimeZone.currentSystemDefault(). Use isBefore to compare against an arbitrary LocalDate.

Code example:

val validate = Validator<LocalDate> { isInPast() }
val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date
validate(now.minus(2, DateTimeUnit.DAY)) // Success
validate(now.plus(2, DateTimeUnit.DAY)) // Failure (message: Must be in the past)

@JvmName(name = "localTimeIsInPast")
fun Validatable<LocalTime?>.isInPast(): Constraint

The validatable LocalTime must be in the past when this constraint is applied.

The comparison is made against the system clock Clock.System and time zone TimeZone.currentSystemDefault(). Use isBefore to compare against an arbitrary LocalTime.

Code example:

val validate = Validator<LocalTime> { isInPast() }
val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).time
validate(LocalTime.fromSecondOfDay(now.toSecondOfDay() - 5)) // Success
validate(LocalTime.fromSecondOfDay(now.toSecondOfDay() + 5)) // Failure (message: Must be in the past)

@JvmName(name = "localDateTimeIsInPast")
fun Validatable<LocalDateTime?>.isInPast(): Constraint

The validatable LocalDateTime must be in the past when this constraint is applied.

The comparison is made against the system clock Clock.System and time zone TimeZone.currentSystemDefault(). Use isBefore to compare against an arbitrary LocalDateTime.

Code example:

val validate = Validator<LocalDateTime> { isInPast() }
val timezone = TimeZone.currentSystemDefault()
val now = Clock.System.now().toLocalDateTime(timezone)
validate((now.toInstant(timezone) - 5.seconds).toLocalDateTime(timezone)) // Success
validate((now.toInstant(timezone) + 5.seconds).toLocalDateTime(timezone)) // Failure (message: Must be in the past)