# Behavior traces — iamkun/dayjs

> Canonical page: https://codevetter.com/unpack/dayjs/behavior-traces

# Behavior traces — iamkun/dayjs

Scanned commit 436bde0bcded312781cbe45dc2b0ef079a36d8e3 (2026-09-15). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

Eight traces follow concrete public operations through their implementation branches. They cover initial construction, calendar manipulation, locale registration, strict parsing, timezone parsing/conversion, durations, and serialization. Each trace describes source execution order rather than an observed runtime result. Persistence here is the caller-facing serialization boundary.
- Construction: module initialization loads English → dayjs('2024-03-20') attaches configuration → Dayjs constructor selects $L → parse calls parseDate → init caches local fields → constructor assigns $x and the Dayjs marker. — [src/index.js#L1-L7](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L1-L7) [src/index.js#L39-L48](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L39-L48) [src/index.js#L63-L108](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L63-L108)
- Month arithmetic/display: dayjs('2024-01-31').add(1, 'month') → prettyUnit → set → clone → $set moves to day 1 and clamps to destination daysInMonth → init → format replaces YYYY/MM/DD tokens; the core setter leaves the original date intact. — [src/utils.js#L30-L43](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/utils.js#L30-L43) [src/index.js#L194-L240](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L194-L240) [src/index.js#L285-L302](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L285-L302) [src/index.js#L391-L408](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L391-L408)
- Locale display: importing zh-cn calls dayjs.locale(locale, null, true) → parseLocale registers the object without selecting it globally → instance.locale('zh-cn') clones and changes $L → format reads translated month/day/meridiem data. — [src/locale/zh-cn.js#L4-L10](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/locale/zh-cn.js#L4-L10) [src/locale/zh-cn.js#L48-L67](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/locale/zh-cn.js#L48-L67) [src/index.js#L14-L36](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L14-L36) [src/index.js#L262-L282](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L262-L282) [src/index.js#L399-L408](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L399-L408)
- Strict parsing: extend(customParseFormat) installs its parse wrapper → dayjs(input, format, true) preserves arguments → parseFormattedInput calls makeParser and constructs a Date → init → format(format) comparison invalidates mismatches; format arrays recursively try candidates until one is valid. — [src/index.js#L39-L47](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L39-L47) [src/index.js#L448-L453](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L448-L453) [src/plugin/customParseFormat/index.js#L181-L213](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/customParseFormat/index.js#L181-L213) [src/plugin/customParseFormat/index.js#L224-L268](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/customParseFormat/index.js#L224-L268)
- Named-zone construction: with UTC installed, dayjs.tz(string, zone) → tzOffset(now, zone) chooses an initial offset → dayjs.utc(string, optionalFormat).valueOf() obtains wall-clock fields → fixOffset reconciles guesses or a DST gap → dayjs(targetTs).utcOffset(targetOffset) → stores $timezone; invalid parsed input returns an invalid instance. — [src/plugin/timezone/index.js#L45-L90](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/timezone/index.js#L45-L90) [src/plugin/timezone/index.js#L135-L152](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/timezone/index.js#L135-L152) [src/plugin/utc/index.js#L26-L29](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/utc/index.js#L26-L29) [src/plugin/utc/index.js#L89-L109](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/utc/index.js#L89-L109)
- Zone conversion: instance.tz(zone, keepLocalTime) returns immediately for invalid state → toDate → toLocaleString and tzOffset → UTC conversion for zero offset or localized reconstruction otherwise → restore milliseconds and set offset → optionally add oldOffset-newOffset → attach $timezone. — [src/plugin/timezone/index.js#L95-L114](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/timezone/index.js#L95-L114) [src/plugin/utc/index.js#L71-L109](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/utc/index.js#L71-L109)
- Duration arithmetic: dayjs.duration(object) captures the global locale → Duration normalizes component keys and calculates $ms → date.add(duration) detects Duration → manipulateDuration applies years, months, days, hours, minutes, seconds, and milliseconds in order; humanize separately calls fromNow and therefore needs relativeTime. — [src/plugin/duration/index.js#L76-L107](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/duration/index.js#L76-L107) [src/plugin/duration/index.js#L232-L237](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/duration/index.js#L232-L237) [src/plugin/duration/index.js#L261-L287](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/duration/index.js#L261-L287) [src/plugin/relativeTime/index.js#L89-L90](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/relativeTime/index.js#L89-L90)
- Serialization: JSON.stringify(instance) reaches toJSON → isValid → toISOString for valid state or null otherwise; UTC overrides toISOString to use toDate, which calls offset-adjusted valueOf before native ISO serialization. — [src/index.js#L115-L117](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L115-L117) [src/index.js#L411-L423](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/index.js#L411-L423) [src/plugin/utc/index.js#L119-L142](https://github.com/iamkun/dayjs/blob/436bde0bcded312781cbe45dc2b0ef079a36d8e3/src/plugin/utc/index.js#L119-L142)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
