Temporal ValueRange Checks Calendar Bounds

Query LocalDate.range(ChronoField.DAY_OF_MONTH) to inspect month-specific ValueRange bounds and validate candidate days before construction.

JavaForm Validation

Code

snippet
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;

public class CalendarRangeGuard {

    public static void main(String[] args) {
        ValueRange genericDom = ChronoField.DAY_OF_MONTH.range();
        System.out.println("generic DOM: " + genericDom
                + " fixed=" + genericDom.isFixed()
                + " smallestMax=" + genericDom.getSmallestMaximum());

        ValueRange leapFeb = LocalDate.of(2024, 2, 1).range(ChronoField.DAY_OF_MONTH);
        ValueRange commonFeb = LocalDate.of(2026, 2, 1).range(ChronoField.DAY_OF_MONTH);

        System.out.println("2024-02 valid 29: " + leapFeb.isValidIntValue(29));
        System.out.println("2026-02 valid 29: " + commonFeb.isValidIntValue(29));
        System.out.println("2026-02 bounds:   " + commonFeb.getMinimum() + ".." + commonFeb.getMaximum());

        try {
            commonFeb.checkValidIntValue(29, ChronoField.DAY_OF_MONTH);
        } catch (DateTimeException ex) {
            System.out.println("rejected day 29: " + ex.getMessage());
        }
    }
}

Logic trace — Temporal ValueRange Checks Calendar Bounds

Under the hood: the class CalendarRangeGuard and the function main.

Watch out for

  • Copy, run: the standard library answers every call in the file.

Putting it to use

Primary entry header declares public static void main(String[] args)

Output lines are prefixed (generic DOM:, 2024-02 valid 29:, 2026-02 valid 29:), displaying intermediate results explicitly inside printed console lines.

Core lines

ValueRange commonFeb = LocalDate.of(2026, 2, 1).range(ChronoField.DAY_OF_MONTH);
ValueRange leapFeb = LocalDate.of(2024, 2, 1).range(ChronoField.DAY_OF_MONTH);
commonFeb.checkValidIntValue(29, ChronoField.DAY_OF_MONTH);

Interactive Tools for This Topic

FAQ

What does Temporal ValueRange Checks Calendar Bounds print when run?
The script runs standalone; its 5 labeled outputs include `generic DOM:`, `2024-02 valid 29:`, `2026-02 valid 29:`.