CodeVetter · Repo Unpack · Data flow
moment/luxon
Inputs enter through explicit factories and are normalized into calendar fields, unit quantities, or endpoints. Parsing carries extracted zones separately from date fields before construction resolves defaults, validates data, and computes a timestamp. Transformations create new temporal objects, with calendar arithmetic distinguished from elapsed-time arithmetic. Output methods emit strings, numbers, objects, or native Dates; durable storage remains the caller's responsibility.
- normalizeObject processes own properties, skips null/undefined values, canonicalizes unit names, and coerces numbers; asNumber rejects booleans, empty strings, and non-finite results.
- ISO parsing tries anchored Gregorian, week, ordinal, and time patterns, returning fields and a Zone; parseDataToDateTime interprets in the parsed zone and converts to the requested/default zone unless setZone is true.
- Custom-format input becomes parsed tokens, macro expansions, regex handlers, and matched fields; parseFromTokens forwards result, zone, specificOffset, and invalidReason into DateTime construction.
- fromObject fills omitted higher-order fields from the current/reference date and lower-order fields from defaults, validates the selected calendar, then converts week/ordinal values to Gregorian fields and resolves timestamp/offset.
- DateTime owns ts, zone, locale, calendar fields, offset, validity, and wasHole; clone carries these forward into a new instance and the constructor reuses derived fields when timestamp and zone are unchanged.
- plus/minus normalize duration-like inputs; adjustTime changes calendar fields first, resolves DST, adds residual elapsed milliseconds, and recalculates the offset after that addition.
- Localized output flows through Formatter, Locale.dtFormatter, and cached Intl.DateTimeFormat instances; unsupported fixed/custom zones are represented via shifted UTC Dates and substituted zone-name parts.
- DateTime.toJSON emits ISO text and toBSON emits a native Date; Duration.toJSON emits ISO duration text, while Interval.toISO emits start/end strings, so these paths transfer values without writing application storage.