# iamkun/dayjs architecture

> Architecture diagram of the GitHub repository iamkun/dayjs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/iamkun/dayjs
- Repository: https://github.com/iamkun/dayjs

## Overview

Day.js is a lightweight, immutable date-and-time library. Its principal workflow is to construct a date from input, validate and manipulate it through a chainable API, then query or format the result. Locale handling and opt-in plugins extend that core with parsing formats, durations, calendar and week operations, relative time, and UTC/time-zone support. The graph reflects the README’s capability descriptions and the sampled source; relationships for unsampled plugin implementations are not inferred beyond documented plugin loading.

Main entry points: [`src/index.js`](https://github.com/iamkun/dayjs/blob/dev/src/index.js) (Day.js API), [`src/constant.js`](https://github.com/iamkun/dayjs/blob/dev/src/constant.js) (Time constants), [`src/plugin/timezone/index.js`](https://github.com/iamkun/dayjs/blob/dev/src/plugin/timezone/index.js) (Time-zone conversion), [`src/plugin/utc/index.js`](https://github.com/iamkun/dayjs/blob/dev/src/plugin/utc/index.js) (UTC offsets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core date API"]
  node_entry["Day.js API<br/>[index.js]"]
  node_parse["Date parsing<br/>[index.js]"]
  node_manipulate["Date operations<br/>[index.js]"]
  node_query["Date queries<br/>[index.js]"]
  node_format["Date formatting<br/>[index.js]"]
  node_utils["Date utilities<br/>[utils.js]"]
  node_constants["Time constants<br/>[constant.js]"]
end

subgraph group_locale["Locale and parsing"]
  node_locale["Locale management<br/>[index.js]"]
  node_locale_data["Locale data API<br/>[index.js]"]
  node_localized_format["Localized formats<br/>[utils.js]"]
  node_custom_parse["Custom format parsing<br/>[index.js]"]
end

subgraph group_calendar["Calendar extensions"]
  node_duration["Duration arithmetic<br/>[index.js]"]
  node_week["Week calculations<br/>[index.js]"]
  node_calendar_plugins["Calendar plugins"]
  node_relative["Relative time<br/>[index.js]"]
end

subgraph group_time["Time-zone extensions"]
  node_utc["UTC offsets<br/>[index.js]"]
  node_timezone["Time-zone conversion<br/>[index.js]"]
  node_time_plugins["Time plugins"]
end

node_user(("Library consumer"))

node_user -->|"uses date API"| node_entry
node_entry -->|"parses input"| node_parse
node_entry -->|"manipulates dates"| node_manipulate
node_entry -->|"queries dates"| node_query
node_entry -->|"formats dates"| node_format
node_entry -->|"uses utilities"| node_utils
node_entry -->|"uses constants"| node_constants
node_entry -->|"manages locales"| node_locale
node_user -.->|"loads optionally"| node_locale_data
node_user -.->|"loads optionally"| node_localized_format
node_user -.->|"loads optionally"| node_custom_parse
node_custom_parse -->|"uses format helpers"| node_localized_format
node_locale_data -->|"uses format helpers"| node_localized_format
node_user -.->|"loads optionally"| node_duration
node_user -.->|"loads optionally"| node_week
node_user -.->|"loads optionally"| node_relative
node_user -.->|"loads optionally"| node_calendar_plugins
node_duration -->|"uses time constants"| node_constants
node_week -->|"uses unit constants"| node_constants
node_relative -->|"uses time constants"| node_constants
node_user -.->|"loads optionally"| node_utc
node_user -.->|"loads optionally"| node_timezone
node_user -.->|"loads optionally"| node_time_plugins
node_utc -->|"uses offset constants"| node_constants
node_timezone -->|"uses time constants"| node_constants
node_timezone -->|"calls UTC API"| node_utc

click node_entry "https://github.com/iamkun/dayjs/blob/dev/src/index.js"
click node_parse "https://github.com/iamkun/dayjs/blob/dev/src/index.js"
click node_manipulate "https://github.com/iamkun/dayjs/blob/dev/src/index.js"
click node_query "https://github.com/iamkun/dayjs/blob/dev/src/index.js"
click node_format "https://github.com/iamkun/dayjs/blob/dev/src/index.js"
click node_utils "https://github.com/iamkun/dayjs/blob/dev/src/utils.js"
click node_constants "https://github.com/iamkun/dayjs/blob/dev/src/constant.js"
click node_locale "https://github.com/iamkun/dayjs/blob/dev/src/index.js"
click node_locale_data "https://github.com/iamkun/dayjs/blob/dev/src/plugin/localeData/index.js"
click node_localized_format "https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/utils.js"
click node_custom_parse "https://github.com/iamkun/dayjs/blob/dev/src/plugin/customParseFormat/index.js"
click node_duration "https://github.com/iamkun/dayjs/blob/dev/src/plugin/duration/index.js"
click node_week "https://github.com/iamkun/dayjs/blob/dev/src/plugin/isoWeek/index.js"
click node_calendar_plugins "https://github.com/iamkun/dayjs/tree/dev/src/plugin"
click node_relative "https://github.com/iamkun/dayjs/blob/dev/src/plugin/relativeTime/index.js"
click node_utc "https://github.com/iamkun/dayjs/blob/dev/src/plugin/utc/index.js"
click node_timezone "https://github.com/iamkun/dayjs/blob/dev/src/plugin/timezone/index.js"
click node_time_plugins "https://github.com/iamkun/dayjs/tree/dev/src/plugin"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_parse,node_manipulate,node_query,node_format,node_utils,node_constants toneBlue
class node_locale,node_locale_data,node_localized_format,node_custom_parse toneAmber
class node_duration,node_week,node_calendar_plugins,node_relative toneMint
class node_utc,node_timezone,node_time_plugins toneRose
class node_user toneIndigo
```

## Components

### Core date API

- [Day.js API](https://github.com/iamkun/dayjs/blob/dev/src/index.js): `src/index.js`
- [Date parsing](https://github.com/iamkun/dayjs/blob/dev/src/index.js): `src/index.js`
- [Date operations](https://github.com/iamkun/dayjs/blob/dev/src/index.js): `src/index.js`
- [Date queries](https://github.com/iamkun/dayjs/blob/dev/src/index.js): `src/index.js`
- [Date formatting](https://github.com/iamkun/dayjs/blob/dev/src/index.js): `src/index.js`
- [Date utilities](https://github.com/iamkun/dayjs/blob/dev/src/utils.js): `src/utils.js`
- [Time constants](https://github.com/iamkun/dayjs/blob/dev/src/constant.js): `src/constant.js`

### Locale and parsing

- [Locale management](https://github.com/iamkun/dayjs/blob/dev/src/index.js): `src/index.js`
- [Locale data API](https://github.com/iamkun/dayjs/blob/dev/src/plugin/localeData/index.js): `src/plugin/localeData/index.js`
- [Localized formats](https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/utils.js): `src/plugin/localizedFormat/utils.js`
- [Custom format parsing](https://github.com/iamkun/dayjs/blob/dev/src/plugin/customParseFormat/index.js): `src/plugin/customParseFormat/index.js`

### Calendar extensions

- [Duration arithmetic](https://github.com/iamkun/dayjs/blob/dev/src/plugin/duration/index.js): `src/plugin/duration/index.js`
- [Week calculations](https://github.com/iamkun/dayjs/blob/dev/src/plugin/isoWeek/index.js): `src/plugin/isoWeek/index.js`
- [Calendar plugins](https://github.com/iamkun/dayjs/tree/dev/src/plugin): `src/plugin`
- [Relative time](https://github.com/iamkun/dayjs/blob/dev/src/plugin/relativeTime/index.js): `src/plugin/relativeTime/index.js`

### Time-zone extensions

- [UTC offsets](https://github.com/iamkun/dayjs/blob/dev/src/plugin/utc/index.js): `src/plugin/utc/index.js`
- [Time-zone conversion](https://github.com/iamkun/dayjs/blob/dev/src/plugin/timezone/index.js): `src/plugin/timezone/index.js`
- [Time plugins](https://github.com/iamkun/dayjs/tree/dev/src/plugin): `src/plugin`

### Other components

- **Library consumer**

## Connections

- Library consumer → Day.js API: uses date API
- Day.js API → Date parsing: parses input (evidence: `src/index.js`)
- Day.js API → Date operations: manipulates dates (evidence: `src/index.js`)
- Day.js API → Date queries: queries dates (evidence: `src/index.js`)
- Day.js API → Date formatting: formats dates (evidence: `src/index.js`)
- Day.js API → Date utilities: uses utilities (evidence: `src/index.js`)
- Day.js API → Time constants: uses constants (evidence: `src/index.js`)
- Day.js API → Locale management: manages locales (evidence: `src/index.js`)
- Library consumer → Locale data API: loads optionally
- Library consumer → Localized formats: loads optionally
- Library consumer → Custom format parsing: loads optionally
- Custom format parsing → Localized formats: uses format helpers (evidence: `src/plugin/customParseFormat/index.js`)
- Locale data API → Localized formats: uses format helpers (evidence: `src/plugin/localeData/index.js`)
- Library consumer → Duration arithmetic: loads optionally
- Library consumer → Week calculations: loads optionally
- Library consumer → Relative time: loads optionally
- Library consumer → Calendar plugins: loads optionally
- Duration arithmetic → Time constants: uses time constants (evidence: `src/plugin/duration/index.js`)
- Week calculations → Time constants: uses unit constants (evidence: `src/plugin/isoWeek/index.js`)
- Relative time → Time constants: uses time constants (evidence: `src/plugin/relativeTime/index.js`)
- Library consumer → UTC offsets: loads optionally
- Library consumer → Time-zone conversion: loads optionally
- Library consumer → Time plugins: loads optionally
- UTC offsets → Time constants: uses offset constants (evidence: `src/plugin/utc/index.js`)
- Time-zone conversion → Time constants: uses time constants (evidence: `src/plugin/timezone/index.js`)
- Time-zone conversion → UTC offsets: calls UTC API (evidence: `src/plugin/timezone/index.js`)
