Fundamentals
    Preparing search index...

    Class DateOnly

    Represents a date with no time and no time zone - a day on a calendar.

    Deliberately not a JavaScript Date. A Date is an instant, and a calendar date is not one: turning 2026-05-12 into a Date produces UTC midnight, which every browser-local getter west of UTC reads back as the 11th. That is a wrong answer that looks right, and it is only wrong for users in some time zones - which is how it survives development in others.

    Holding the three parts the server sent means there is no instant to convert and nothing to shift. Where a Date is genuinely wanted - to feed a date picker, or to do arithmetic - toDate constructs one in the local time zone, and the choice is then visible at the call site making it.

    Index
    day: number

    The day of the month, 1 through 31.

    month: number

    The month, 1 through 12.

    year: number

    The year.

    "[typeKey]": "DateOnly" = 'DateOnly'
    • Determines whether this is the same calendar date as another.

      Parameters

      • other: DateOnly | null | undefined

        The other date.

      Returns boolean

      True when they are the same date.

    • Converts to a Date at midnight in the local time zone.

      Returns Date

      The Date.

      Local rather than UTC, so the date a caller reads back with getDate() is the one they started with. This invents a time that was never sent, which is why it is a method to call rather than what the value is.

    • Gets the ISO-8601 representation, yyyy-MM-dd - the same form the server sent.

      Returns string

      The string.

    • Creates a DateOnly from its parts.

      Parameters

      • year: number

        The year.

      • month: number

        The month, 1 through 12.

      • day: number

        The day of the month.

      Returns DateOnly

      The DateOnly.

    • Creates a DateOnly for the calendar date a Date falls on in the local time zone.

      Parameters

      • date: Date

        The date to take the calendar date of.

      Returns DateOnly

      The DateOnly.

      Reads the local parts rather than the UTC ones, because the calendar date a moment falls on is a question only a time zone can answer, and the local one is the one the person looking at the screen is in.

    • Parses the ISO-8601 calendar date the server sends, yyyy-MM-dd.

      Parameters

      • value: string

        The value to parse.

      Returns DateOnly

      The DateOnly.