Millwork
    Preparing search index...

    Module @millwork-ts/luxon

    @millwork-ts/luxon

    Millwork codecs for luxon. Each codec reads a wire value into a luxon DateTime, Duration or Interval, and writes it back.

    pnpm add @millwork-ts/core @millwork-ts/luxon luxon
    

    Each codec is a named export. The codecs record has each codec two times: with its kind as the key (date) and with the adapter prefix (luxon:date). The name of each codec has the prefix. If your app registers two date families, use the prefixed keys.

    Export Key Wire Value
    date date "2026-12-01" DateTime, local midnight of that day
    datetime datetime RFC 3339, "2026-12-01T14:30:00-05:00" or "…Z" DateTime, local zone
    epoch epoch a number, or a string for large values DateTime, local zone
    time time "14:30", "14:30:00.123" DateTime of today, in UTC
    localDateTime local-datetime "2026-12-01T14:30:00" DateTime in UTC
    zonedDateTime zoned-datetime "2026-12-01T14:30:00-05:00[America/Toronto]", { at, zone } DateTime in that zone
    yearMonth year-month "2026-12" DateTime, local midnight of day 1
    duration duration ISO 8601 "PT1H30M", or a number Duration
    interval interval "a/b", "a/PT1H", "P1D/b", { start, end } Interval

    Options:

    • datetime: keepOffset: true keeps the wire offset in the value (luxon setZone: true), and serialize writes that offset. Without it, serialize writes Z.
    • epoch: unit is 's', 'ms' (the default), 'us' or 'ns'. serialize writes a number when it is a safe integer. It writes 'ns' as a string. luxon keeps milliseconds only.
    • zonedDateTime: wire: 'object' writes { at, zone }. The default writes RFC 9557. Both are read. The wire offset must be the offset of the zone at that instant, or the value is bad.
    • duration: unit is 'iso' (the default), 's' or 'ms'. A duration with years, months or weeks cannot become a number, so serialize throws a RangeError. A day is 24 hours.
    • interval: wire: 'object' writes { start, end }. A duration is added in UTC. An open interval (..) is bad input.

    time and local-datetime values are in UTC, so a DST gap in the local zone cannot move the wall clock. To put one in a zone, use setZone(zone, { keepLocalTime: true }).

    Bad wire input gives undefined and a report to onInvalid. A value of the wrong type, or an invalid luxon value, makes serialize throw a TypeError.

    • datetime, epoch and interval compare the instant (+a === +b), not the zone or the locale.
    • zonedDateTime compares the instant and the zone name.
    • luxonFamily.datetime({ strict: true }) (also epoch, zonedDateTime and interval) gives a codec that uses luxon equals, which also compares the zone and the locale.
    • date, time, local-datetime and year-month compare the wire text.
    • duration compares years, months and weeks one by one, and the other units by length. PT1H equals PT60M. P1M does not equal P30D.

    Register the codecs before the store calls transformations(), because transformations() reads the registry when it runs. See the @millwork-ts/warp-drive README.

    import { codecs } from '@millwork-ts/luxon'
    import { registerCodecs, valueField } from '@millwork-ts/warp-drive'
    import { withDefaults } from '@warp-drive/core/reactive'

    registerCodecs(codecs)

    export const EventSchema = withDefaults({
    type: 'event',
    fields: [
    valueField('startsOn', 'luxon:date'),
    valueField('startsAt', 'luxon:datetime', { keepOffset: true }),
    valueField('length', 'luxon:duration'),
    ],
    })
    IntervalOptions
    LuxonTypes
    StrictOptions
    ZonedOptions
    IntervalRaw
    ZonedRaw
    codecs
    date
    datetime
    duration
    epoch
    interval
    localDateTime
    luxonFamily
    time
    yearMonth
    zonedDateTime