CodeVetter · Repo Unpack · Data flow
iamkun/dayjs
Inputs pass through the factory and an overridable parsing boundary into native Date state. Cached fields drive most calendar operations and display, while valueOf provides the epoch boundary for comparisons and elapsed-time calculations. Clones retain locale and extension metadata, and optional plugins reinterpret parsing, offsets, or output. Serialization returns values to the caller; the inspected runtime does not implement durable persistence.
- dayjs(date, c) clones recognized Dayjs inputs; otherwise it reuses an object configuration or creates one, attaches date and original arguments, and passes it to new Dayjs.
- parseDate maps null to an invalid Date, undefined to now, and Date objects to copies; matching non-Z strings become local or UTC components with milliseconds truncated to three digits, while other inputs use native Date parsing.
- parse stores the Date and invokes init to cache calendar fields; wrapper propagates $L, $u, $x, and $offset into new instances, and clone uses that wrapper.
- set clones before $set; month/year changes temporarily move to day 1 and clamp the original day, while add branches between calendar changes for months/years/days/weeks and timestamp increments for smaller units.
- format resolves the instance's current registry locale, rejects invalid state with a locale-specific message or Invalid Date, and replaces recognized tokens while preserving bracket literals.
- customParseFormat tokenizes a format into regex/parser entries, accumulates fields, corrects meridiem hours, constructs a Date with defaults and offset handling, then optionally invalidates a nonmatching strict round trip.
- Named-zone string parsing converts wall-clock fields through UTC, reconciles an offset guess against Intl-derived offsets, and stores the result in $offset and $x.$timezone; UTC valueOf subtracts offset bookkeeping to recover the instant.
- toDate creates a fresh Date from valueOf; toJSON emits ISO for valid dates and null for invalid dates. Duration JSON instead emits an ISO duration string, and named-zone/locale metadata is not included in these outputs.