Skip to content

Views and Snapshots

A ZView is a projection of an instant through a zone, calendar, and locale. Every ZDate exposes two: utc and local. Views are lazy — fields resolve on first read and are cached — and they are read-only: a view can never change the instant it projects.

Fields

GetterDescription
year, month, day, eraCalendar fields in the view's calendar
hour, minute, second, nanosecondClock fields in the view's zone
epochThe projected instant's identity
zoneZTimeZone for this view
calendarZCalendar for this view
localeZLocale for this view

Derived Fields

GetterDescription
leapYearCalendar-aware leap year
daysInMonth / daysInYearCalendar-aware lengths
dayOfWeekISO day 1–7
dayOfYear / weekOfYear / isoQuarterPosition within the year
firstDayOfWeekCalendar's first weekday
monthName / monthAbbrLocalized month names
weekdayName / weekdayAbbrLocalized weekday names
dayPeriodLocalized AM/PM

toString() renders the view as RFC 9557.

Snapshots

snapshot() captures a view's fields as a plain serializable object, and a snapshot is accepted by the ZDate constructor — the memento pattern. This is why the method is on ZView and not named toObject/fromObject on ZDate: a snapshot records a view of the instant (fields as seen through a zone and calendar), and restoring it reconstructs the same instant from that record.

ts
const snap = d.local.snapshot()   // plain object; also what toJSON() emits
const restored = new ZDate(snap)  // same instant

Use snapshots to persist or transmit a date with its view context intact, without inventing a custom serialization.