$ show iamkun/dayjs
Day.js is a lightweight JavaScript date/time library (approximately 2 kB gzipped) designed as a drop-in alternative to Moment.js. It provides immutable, chainable parsing, validation, manipulation, formatting, and comparison APIs, along with extensive internationalization support via over 100 locale files. The library is built as a modular core with a plugin system that extends functionality without bloating the base bundle. It runs in both browsers and Node.js, includes TypeScript definitions, and has a comprehensive test suite that ensures behavioral parity with Moment.js. This is a library, not an application or data pipelineβthere are no server components, CLI tools, or data analysis artifacts. The architecture is intentionally small and focused, with a constant-driven unit system and a clean separation between core, plugins, and locales.
The LLM identified 3 files worth highlighting for reuse:
A self-contained plugin that adds timezone support to dayjs. It implements conversion between arbitrary timezones using the Intl API, handles DST edge cases, and exposes methods like `tz()` and `utcOffset()`. The plugin is completely decoupled from the coreβit only uses the dayjs instance and prototype methodsβmaking it easily extractable for other projects that need timezone-aware date handling without pulling in a heavy date library. It demonstrates sophisticated handling of IANA timezone names and offset calculations.
Implements a `Duration` class as a plugin that adds duration arithmetic and formatting capabilities. It provides methods for adding, subtracting, comparing, and converting durations, as well as flexible formatting similar to Moment.js. The plugin is designed to work independently and can be reused in any date-related project that needs duration support. It showcases a clean, functional approach to handling time intervals without modifying the core API.
A collection of pure utility functions used across the core and plugins, including `padStart`, `padZoneStr`, `monthDiff`, `absFloor`, `prettyUnit`, and `isUndefined`. These are atomic, dependency-free helpers that solve common date math problems (diffing months, floor rounding, unit normalization). They are trivially reusable in any JavaScript project dealing with date manipulation and demonstrate a concise, functional style.