Teki
Rules

Truncate To

Truncate a temporal value to a given unit and normalize it to an Instant.

Use truncateTo(ChronoUnit) to strip sub-unit precision from a temporal field and resolve it as a java.time.Instant.

import java.time.temporal.ChronoUnit;
import static dev.ditsche.teki.rule.builder.Rules.*;

Teki schema = Teki.fromRules(
    temporal("scheduledAt").required().truncateTo(ChronoUnit.DAYS),
    temporal("recordedAt").truncateTo(ChronoUnit.HOURS)
);

After validation succeeds, Teki writes the truncated Instant back to the field.

Supported units

truncateTo delegates to Instant.truncatedTo(ChronoUnit). The following units are supported:

UnitExample result for 2024-06-15T14:32:55.123Z
NANOS2024-06-15T14:32:55.123Z
MICROS2024-06-15T14:32:55.123Z
MILLIS2024-06-15T14:32:55.123Z
SECONDS2024-06-15T14:32:55Z
MINUTES2024-06-15T14:32:00Z
HOURS2024-06-15T14:00:00Z
HALF_DAYS2024-06-15T12:00:00Z
DAYS2024-06-15T00:00:00Z

Units larger than DAYS (WEEKS, MONTHS, YEARS) are not supported by Instant.truncatedTo and will cause validation to fail.

Available on

  • temporal(...)

Annotation equivalent

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

public class EventRequest {
    @TruncateTo(ChronoUnit.DAYS)
    private ZonedDateTime scheduledAt;
}

On this page