> ## 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.

# Calendar

> Age, today, weekdays and windows of time around now.

Rules about the calendar. `minAge`, `maxAge`, `today`, `withinNext` and `withinLast` read the
[clock of the configuration](https://validity-kt.dev/guides/time.md), so tests can fix it. The windows take a `kotlin.time.Duration`, such as
`30.days`.

> [!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 Appointment.kt theme={null}
data class Appointment(
    val date: LocalDate?,
    val patientBirthDate: LocalDate?
) : Validatable {
    override fun validation() = validation {
        ::date required {
            weekday()
            withinNext(60.days)
        }
        ::patientBirthDate required { maxAge(120) }
    }
}
```

| Constraint | Checks |
| - | - |
| [`minAge`](#minage) | Someone born on the date is at least `min` years old today. |
| [`maxAge`](#maxage) | Someone born on the date is at most `max` years old today. |
| [`today`](#today) | Falls on today. |
| [`withinNext`](#withinnext) | Is between today and `duration` from today, both included. |
| [`withinLast`](#withinlast) | Is between `duration` before today and today, both included. |
| [`weekday`](#weekday) | Falls from Monday to Friday. |
| [`weekend`](#weekend) | Falls on a Saturday or a Sunday. |

## Age

### `minAge`

`minAge(min)` on `LocalDate`

Checks that someone born on the date is at least `min` years old today.

**Code** `minAge`· **Message** `must be at least {min} years old` · **Change it** `minAge = "…"`

### `maxAge`

`maxAge(max)` on `LocalDate`

Checks that someone born on the date is at most `max` years old today.

**Code** `maxAge`· **Message** `must be at most {max} years old` · **Change it** `maxAge = "…"`

## Around now

### `today`

`today()` on `LocalDate`, `LocalDateTime`, `ZonedDateTime`, `OffsetDateTime`

Checks that the date falls on today.

It is moved to the zone of the clock before its date is compared.

**Code** `today`· **Message** `must be today` · **Change it** `today = "…"`

### `withinNext`

`withinNext(duration)` on `LocalDate`, `LocalDateTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`

Checks that the date is between today and `duration` from today, both included.

**Code** `withinNext`· **Message** `must be within the next {duration}` · **Change it** `withinNext = "…"`

### `withinLast`

`withinLast(duration)` on `LocalDate`, `LocalDateTime`, `ZonedDateTime`, `OffsetDateTime`, `Instant`

Checks that the date is between `duration` before today and today, both included.

**Code** `withinLast`· **Message** `must be within the last {duration}` · **Change it** `withinLast = "…"`

## Days of the week

### `weekday`

`weekday()` on `LocalDate`, `LocalDateTime`, `ZonedDateTime`, `OffsetDateTime`

Checks that the date falls from Monday to Friday.

**Code** `weekday`· **Message** `must be a weekday` · **Change it** `weekday = "…"`

### `weekend`

`weekend()` on `LocalDate`, `LocalDateTime`, `ZonedDateTime`, `OffsetDateTime`

Checks that the date falls on a Saturday or a Sunday.

**Code** `weekend`· **Message** `must be on a weekend` · **Change it** `weekend = "…"`


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