Teki
Rules

Temporal

Validate date and time fields.

Use temporal("field") for fields that hold date or time values.

Teki schema = Teki.fromRules(
    temporal("birthDate").required().past(),
    temporal("appointmentAt").futureOrPresent(),
    temporal("expiresAt").after(Instant.parse("2025-01-01T00:00:00Z"))
);

Supported types

temporal() accepts any of the following Java types:

  • java.time.Instant
  • java.time.ZonedDateTime
  • java.time.OffsetDateTime
  • java.time.LocalDateTime
  • java.time.LocalDate
  • java.util.Date
  • java.util.Calendar

Available methods

MethodPurpose
required()Reject missing values
optional()Skip validation when the value is missing
past()Require a date strictly in the past
future()Require a date strictly in the future
pastOrPresent()Require a date in the past or equal to now
futureOrPresent()Require a date in the future or equal to now
before(Instant)Require a date strictly before a fixed boundary
after(Instant)Require a date strictly after a fixed boundary
truncateTo(ChronoUnit)Truncate the value to a unit and resolve as Instant
toUtc()Normalize the value to its Instant representation
toZone(ZoneId)Convert the value to a ZonedDateTime in the given zone
custom(Rule)Attach a custom rule

Annotation equivalent

Temporal fields can use @Past, @Future, @PastOrPresent, @FutureOrPresent, @Before, @After, @TruncateTo, @ToUtc, and @ToZone.

import dev.ditsche.teki.annotation.Future;
import dev.ditsche.teki.annotation.Past;
import dev.ditsche.teki.annotation.TruncateTo;
import dev.ditsche.teki.annotation.ToUtc;
import java.time.temporal.ChronoUnit;

public class EventRequest {
    @Past
    private LocalDate birthDate;

    @Future
    private Instant startsAt;

    @Before("2030-01-01")
    private ZonedDateTime deadline;

    @TruncateTo(ChronoUnit.DAYS)
    private ZonedDateTime scheduledAt;

    @ToUtc
    private OffsetDateTime publishedAt;

    @ToZone("America/New_York")
    private Instant meetingAt;
}

On this page