> ## Documentation Index
> Fetch the complete documentation index at: https://validity-kt.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Dates and times

> Past, future and comparisons for LocalDate, Instant, ZonedDateTime, YearMonth, java.util.Date and the other java.time types.

The constraints of `java.time` values, and of `java.util.Date`. `past`, `future` and their `OrPresent` forms read the
[clock of the configuration](https://validity-kt.dev/guides/time.md). The comparisons take a value of the same type.

> [!NOTE]
>
> A `null` argument checks nothing. A rule that reads a value that may be missing, such as `max(customer.limit)`,
> never fails because of it: `required` on that value reports it once.

```kotlin Event.kt theme={null}
data class Event(
    val startsAt: OffsetDateTime?,
    val endsAt: OffsetDateTime?,
    val announcedOn: LocalDate? = null
) : Validatable {
    override fun validation() = validation {
        ::startsAt required { future() }
        ::endsAt required { after(startsAt) }
        ::announcedOn ifPresent { pastOrPresent() }
    }
}
```

| Constraint | Checks |
| - | - |
| [`past`](#past) | Is before now. |
| [`future`](#future) | Is after now. |
| [`pastOrPresent`](#pastorpresent) | Is now or before. |
| [`futureOrPresent`](#futureorpresent) | Is now or after. |
| [`after`](#after) | Is after `other`. |
| [`before`](#before) | Is before `other`. |
| [`afterOrEqual`](#afterorequal) | Is `other` or after. |
| [`beforeOrEqual`](#beforeorequal) | Is `other` or before. |
| [`between`](#between) | Is between `start` and `end`, both included. |

## Relative to now

### `past`

`past()` on `LocalDate`, `LocalDateTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`, `YearMonth`, `Year`, `Date`

Checks that the date is before now.

**Code** `past`· **Message** `must be in the past` · **Change it** `past = "…"`

### `future`

`future()` on `LocalDate`, `LocalDateTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`, `YearMonth`, `Year`, `Date`

Checks that the date is after now.

**Code** `future`· **Message** `must be in the future` · **Change it** `future = "…"`

### `pastOrPresent`

`pastOrPresent()` on `LocalDate`, `LocalDateTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`, `YearMonth`, `Year`, `Date`

Checks that the date is now or before.

**Code** `pastOrPresent`· **Message** `must be in the past or present` · **Change it** `pastOrPresent = "…"`

### `futureOrPresent`

`futureOrPresent()` on `LocalDate`, `LocalDateTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`, `YearMonth`, `Year`, `Date`

Checks that the date is now or after.

**Code** `futureOrPresent`· **Message** `must be in the future or present` · **Change it** `futureOrPresent = "…"`

## Comparisons

### `after`

`after(other)` on `LocalDate`, `LocalDateTime`, `LocalTime`, `OffsetTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`, `YearMonth`, `Year`, `Date`

Checks that the date is after `other`.

**Code** `after`· **Message** `must be after {other}` · **Change it** `after = "…"`

### `before`

`before(other)` on `LocalDate`, `LocalDateTime`, `LocalTime`, `OffsetTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`, `YearMonth`, `Year`, `Date`

Checks that the date is before `other`.

**Code** `before`· **Message** `must be before {other}` · **Change it** `before = "…"`

### `afterOrEqual`

`afterOrEqual(other)` on `LocalDate`, `LocalDateTime`, `LocalTime`, `OffsetTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`, `YearMonth`, `Year`, `Date`

Checks that the date is `other` or after.

**Code** `afterOrEqual`· **Message** `must be after or equal to {other}` · **Change it** `afterOrEqual = "…"`

### `beforeOrEqual`

`beforeOrEqual(other)` on `LocalDate`, `LocalDateTime`, `LocalTime`, `OffsetTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`, `YearMonth`, `Year`, `Date`

Checks that the date is `other` or before.

**Code** `beforeOrEqual`· **Message** `must be before or equal to {other}` · **Change it** `beforeOrEqual = "…"`

### `between`

`between(start, end)` on `LocalDate`, `LocalDateTime`, `LocalTime`, `OffsetTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`, `YearMonth`, `Year`, `Date`

Checks that the date is between `start` and `end`, both included.

**Code** `between`· **Message** `must be between {start} and {end}` · **Change it** `betweenDates = "…"`

> [!NOTE]
>
> `between` on dates and times is inclusive and uses the message `betweenDates`. Lengths of time, both
> `kotlin.time.Duration` and `java.time.Duration`, have their rules on [Durations](https://validity-kt.dev/constraints/durations.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.