Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion ai/contributing/workflows/docs-writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Use plain developer speech rather than specification jargon:
6. **Avoid tautological openings** under headings (do not follow `` ### `balance()` `` with *"`balance()` balances the duration"*).
7. **Cut filler intensifiers and clichés:** `seamlessly`, `effortlessly`, `powerful`, `first-class`, `under the hood`, `it is worth noting that`, `let's take a look at`.
8. **Do not copy terse source-comment shorthand** into user-facing prose.
9. **Never perform or announce baseline patterns.** Do not sell standard modern practices as features (*"Import only the functions you call so your bundler tree-shakes the rest"*, *"with no extra setup call"*, *"with no registration ceremony"*). State the usage plainly and expect readers to assume baseline quality. Preserve **non-obvious, worthwhile distinctions** that genuinely change behavior or performance (such as automatic `Intl` formatter caching, zero-copy `toTemporal()` unwrapping, or skipping polyfill downloads on native runtimes).
10. **Give each example one canonical home.** Avoid repeating multi-line setup blocks (polyfilling, plugin imports, `configure()` tables) across multiple guides—keep the full walkthrough in one page and link to it from related guides so updates and translations do not multiply.

---

Expand Down Expand Up @@ -111,6 +113,22 @@ Ask whether changing time zones should change what the user sees.
:::
```

## Collapsible Disclosures (`:::details[Title]`)

Use `:::details[Title]` ... `:::` (pass `{open}` only when expanded by default) to fold secondary material that is not necessary on a first read, keeping the happy path short and scannable while leaving deep-dive details one click away:

- **Collapse:** long mid-guide reference tables (such as a full token dictionary or legacy preset aliases), niche escape-hatch options (such as DST `disambiguation` modes), and older-toolchain compatibility notes (`/sync` polyfill loading, older Node caveats).
- **Keep open:** Day-1 requirements that most readers need immediately (such as the primary Safari polyfill command on `Installation`) and primary reference tables on migration guides (`Coming from Day.js`, `Coming from Moment`).
- **Keep titles plain and code narrow:** Use a short sentence-case title with no backticks. Wrap long lines in code blocks inside `:::details` so they fit inside the padded body without horizontal scrollbars. A single table inside `:::details` renders flush without a double border.

```markdown
:::details[Compatibility notes for older runtimes]
- **Synchronous loading:** Import `@native-dates/polyfill/sync` if a module evaluates dates before top-level `await` settles.
:::
```

When two commands or snippets represent **mutually exclusive choices** (such as `npm i` vs. `npx` agent setup), group consecutive fenced blocks with `label="..."` into a single tabbed code block instead of stacking them under separate headings that read like sequential steps.

---

## Astro Markdown and Layout Constraints (`docs/`)
Expand All @@ -124,7 +142,7 @@ Ask whether changing time zones should change what the user sees.
4. **Headings and tables:**
- Never put backticks in `##` headings or `<th>` cells (`docs.css` strips code-chip backgrounds only inside `h1` and `.entry > h3`).
- In 3+ column tables (`.stacks`), the final column **must** be prose because narrow screens (`<= 600px`) render the last cell full-width without a column label. Separate grouped identifiers in earlier columns with commas (`year, month, day`).
- Use `:::truth` around 2-column expression/result tables where `true` and `false` cells render as tinted status words.
- Use `:::truth` around 2-column expression/result tables where `true` and `false` cells render as tinted status words, `:::details[Title]` for collapsible deep-dive blocks, and consecutive `label="..."` code fences for tabbed alternatives.
5. **Inline formatting limits:** Keep inline `` `code` `` spans under ~32 characters (`white-space: nowrap` overflows on `390px` mobile viewports) and avoid attaching suffixes directly onto closing backticks (write `` `DateTime` instances `` rather than `` `DateTime`s ``). In frontmatter `lede` and YAML `description` strings, `inline.js` parses only `` `code` ``, `**strong**`, and `[text](href)` (never `*italic*`).
6. **Verify before finishing:**
- Execute standalone `js` code samples in Node against `src/index.js` and `packages/plugins/src/*.js`.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/guides/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const placed = datetime('2026-11-06T09:05', 'Europe/Berlin');
placed.format('receipt'); // 'Friday, November 6'
```

Named formats work on every type that supports [`format()`](/guides/formatting/), and custom names take precedence over built-in presets.
Named formats apply to dates, times, partial dates, and ranges, while durations use only their built-in styles. Custom names take precedence over built-in presets, so registering `'short'` overrides it across the app.

## Adding plugins

Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/guides/durations.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Without an argument, standalone durations carry months into years and clock unit

Pass `'day'` or `'week'` when you want fixed 24-hour days or 7-day weeks.

Call [`total()`](/api/duration/#total) or its chain-friendly alias [`as()`](/api/duration/#as) to collapse the entire span into a single floating-point number in one unit:
Call [`total()`](/api/duration/#total) or its alias [`as()`](/api/duration/#as) to collapse the entire span into a single floating-point number in one unit:

```js
import { duration } from 'native-dates';
Expand Down
33 changes: 9 additions & 24 deletions docs/src/content/docs/guides/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Native Dates uses the platform's built-in `Intl` formatters and caches them auto

## Quick output with text and presets

Every instance has a `.text` property formatted in your active locale, which is handy for templates, logs, and console debugging. Calling [`format()`](/api/date-time/#format) with no arguments uses each type's default preset:
Every instance has a `.text` property formatted in your active locale. Calling [`format()`](/api/date-time/#format) with no arguments uses each type's default preset:

```js
import { date, datetime, duration, time } from 'native-dates';
Expand All @@ -35,6 +35,7 @@ Pass a preset name to `format()` to choose how much detail to display:
| `'month'` | `'May 2026'` | Full month name and year on `DateTime`, `CalendarDate`, and [`YearMonth`](/api/year-month/). |
| `'text'` | `'May 4, 2026, 9:30 AM PDT'` | Date, time, and short zone name on `DateTime`, or each type's own fields elsewhere. |

:::details[Moment and Day.js preset names]
Core also accepts the localized preset names used in Moment and Day.js:

| Preset | Example | Localized fields |
Expand All @@ -44,6 +45,7 @@ Core also accepts the localized preset names used in Moment and Day.js:
| `'LL'`, `'ll'` | `'May 4, 2026'` | Long or abbreviated month name with day and year. |
| `'LLL'`, `'lll'` | `'May 4, 2026 at 9:30 AM'` | Long or abbreviated date paired with short clock time. |
| `'LLLL'`, `'llll'` | `'Monday, May 4, 2026 at 9:30 AM'` | Full or abbreviated weekday, date, and short clock time. |
:::

Dates, times, [year-months](/api/year-month/), and [month-days](/api/month-day/) accept every preset above and keep only the fields they carry. [Durations](/api/duration/) also support compact and digital styles:

Expand Down Expand Up @@ -102,7 +104,7 @@ Reserve `format()` for text shown to people. When storing values or sending them

## Token patterns

When you need a fixed layout, pass a token pattern directly to `format()` with no plugins required. Wrap literal words in square brackets so they are copied as written:
When you need a fixed layout, pass a token pattern to `format()`. Wrap literal words in square brackets so they are copied as written:

```js
import { datetime, monthDay, yearMonth } from 'native-dates';
Expand All @@ -118,6 +120,7 @@ monthDay('11-16').format('MMMM Do', 'en-US'); // 'November 16th'

Month and weekday names inside token patterns come from `Intl` in the active locale. Digits and years stay in Western ISO form so patterns like `'YYYY-MM-DD'` stay machine-readable everywhere.

:::details[All format tokens]
| Token | Example | Output |
|---|---|---|
| `YYYY` | `'2026'` | Four-digit year, signed for negative years. |
Expand All @@ -144,8 +147,9 @@ Month and weekday names inside token patterns come from `Intl` in the active loc
| `X` | `'1794850200'` | Unix timestamp in whole seconds. |
| `x` | `'1794850200000'` | Unix timestamp in milliseconds. |
| `[text]` | `'[at]'` | Escaped literal text copied straight to the output. |
:::

Unrecognized letters outside square brackets throw an [`unknownFormat`](/api/errors/#units-zones-and-formats) error so a misspelled preset or unbracketed word fails right away instead of printing raw letters. Tokens glued to accented letters like `'às'` or mixed clock letters like `'HHhmm'` throw too, while bare T passes through unescaped for ISO timestamps.
Unrecognized letters outside square brackets throw an [`unknownFormat`](/api/errors/#units-zones-and-formats) error instead of printing raw letters. Tokens glued to accented letters like `'às'` or mixed clock letters like `'HHhmm'` throw too. Bare `T` passes through unescaped for ISO timestamps.

Asking for a field a type does not carry throws an [`unsupportedToken`](/api/errors/#units-zones-and-formats) error instead of inventing midnight. Formatting clock tokens like `'HH:mm'` on a calendar date fails immediately.

Expand All @@ -161,26 +165,7 @@ weekdayNames('narrow', 'monday', 'en-US'); // ['Mo', 'Tu', 'We', ...]

## Naming your own formats

Register reusable format names in [`configure()`](/api/configure/) when your app uses the same date or time layout in multiple places. Each named format can be a token pattern or an `Intl` options object:

```js
import { configure, date, dateRange } from 'native-dates';

configure({
formats: {
invoice: 'YYYY-MM-DD',
receipt: { dateStyle: 'long' },
},
});

date('2026-11-06').format('invoice'); // '2026-11-06'
date('2026-11-06').format('receipt'); // 'November 6, 2026'
dateRange('2026-11-06', '2026-11-20').format('invoice'); // '2026-11-06 – 2026-11-20'

configure({ formats: null });
```

Named formats take precedence over built-in presets, so registering `'short'` overrides that preset across the app. Custom named formats apply to dates, times, partial dates, and ranges, while durations use only their built-in styles.
Register reusable format names in [`configure()`](/api/configure/) when your app reuses a token pattern or `Intl` options object across views. Custom names work on dates, times, partial dates, and ranges, and take precedence over built-in presets. See [Named formats](/guides/customization/#named-formats).

## Formatting ranges

Expand All @@ -199,7 +184,7 @@ shift.format('short', 'en-US'); // '9:00 AM – 5:00 PM'

## Relative phrases

Moments and calendar dates include [`from()`](/api/date-time/#from) and [`fromNow()`](/api/date-time/#fromnow) directly in core, with [`formatRelative()`](/api/date-time/#formatrelative) as an alias. Phrases are localized automatically through the runtime's relative time formatter:
Call [`from()`](/api/date-time/#from) or [`fromNow()`](/api/date-time/#fromnow) on moments and calendar dates for localized phrases through the runtime's relative time formatter. [`formatRelative()`](/api/date-time/#formatrelative) works as an alias:

```js
import { date, datetime, now, today } from 'native-dates';
Expand Down
16 changes: 8 additions & 8 deletions docs/src/content/docs/guides/from-dayjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ dt.format('YYYY-MM-DD HH:mm'); // '2026-11-16 12:30'

## Opt-in plugins

Only non-ISO text parsing, city and abbreviation lookups, and legacy date getters live in [`@native-dates/plugins`](/plugins/). Import each subpath once with no global registration call needed:
Only non-ISO text parsing, city and abbreviation lookups, and legacy date getters live in [`@native-dates/plugins`](/plugins/). Import each subpath once at startup:

```js
import '@native-dates/plugins/loose';
Expand All @@ -102,13 +102,13 @@ date('Nov 16, 2026', { loose: true }); // CalendarDate(2026-11-16)
| `d.day()`, `d.isoWeekday()` | `d.dayOfWeek` | ISO 1 on Monday to 7 on Sunday, with tokens `'E'` for 1–7 and `'d'` for 0–6 |
| `d.unix()`, `d.valueOf()` | `dt.epochSeconds`, `dt.epochMilliseconds` | Each count since 1970 names its unit |
| `d.add(2, 'day')` | `d.plus(2, 'days')` | `add()` and `subtract()` aliases also work |
| `dayjs.tz(x, zone)` | `datetime(x, zone)` | Built into core with no `timezone` plugin |
| `dayjs.tz(x, zone)` | `datetime(x, zone)` | In core, no `timezone` plugin |
| `d.tz(zone)` | `dt.in(zone)` | Views the same moment in another IANA zone |
| `dayjs.utc(x)` | `datetime(x, 'UTC')` | Built into core with no `utc` plugin |
| `dayjs.utc(x)` | `datetime(x, 'UTC')` | In core, no `utc` plugin |
| `b.diff(a, 'day', true)` | `a.until(b, 'days')` | Fractional total in the requested unit |
| `dayjs.duration(90, 'm')` | `minutes(90)` or `duration('90m')` | Built into core with no `duration` plugin |
| `d.format('LLL')` | `dt.format('LLL')` | Localized presets from `'LT'` to `'llll'` in core |
| `d.format('YYYY-MM-DD HH:mm')` | `dt.format('YYYY-MM-DD HH:mm')` | [Token patterns](/guides/formatting/#token-patterns) built directly into core |
| `d.isBetween(a, b)` | `dateRange(a, b).contains(d)` | [Ranges](/api/ranges/) built into core with `to()`, `for()`, and `overlaps()` |
| `d.fromNow()`, `d.from(other)` | `d.fromNow()`, `d.from(other)` | Built into core with no `relativeTime` plugin |
| `dayjs.duration(90, 'm')` | `minutes(90)` or `duration('90m')` | In core, no `duration` plugin |
| `d.format('LLL')` | `dt.format('LLL')` | Localized presets from `'LT'` to `'llll'` |
| `d.format('YYYY-MM-DD HH:mm')` | `dt.format('YYYY-MM-DD HH:mm')` | [Token patterns](/guides/formatting/#token-patterns) in core |
| `d.isBetween(a, b)` | `dateRange(a, b).contains(d)` | [Ranges](/api/ranges/) with `to()`, `for()`, and `overlaps()` |
| `d.fromNow()`, `d.from(other)` | `d.fromNow()`, `d.from(other)` | In core, no `relativeTime` plugin |
| `customParseFormat` | `{ loose: true }` | Provided by [`@native-dates/plugins/loose`](/plugins/loose/) |
12 changes: 6 additions & 6 deletions docs/src/content/docs/guides/from-moment.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ quarter.overlaps(dateRange('2026-12-15', '2027-01-15')); // true
| `m.day()`, `m.isoWeekday()` | `d.dayOfWeek` | ISO 1 on Monday to 7 on Sunday, with tokens `'E'` for 1–7 and `'d'` for 0–6 |
| `m.unix()`, `m.valueOf()` | `dt.epochSeconds`, `dt.epochMilliseconds` | Each count since 1970 names its unit |
| `b.diff(a, 'hours', true)` | `a.until(b, 'hours')` | Fractional total in the requested unit |
| `moment.duration(2, 'h')` | `hours(2)` or `duration('2h')` | Built into core |
| `m.format('LLL')` | `dt.format('LLL')` | Localized presets from `'LT'` to `'llll'` with zero locale files |
| `m.format('YYYY-MM-DD HH:mm')` | `dt.format('YYYY-MM-DD HH:mm')` | [Token patterns](/guides/formatting/#token-patterns) built directly into core |
| `m.isBetween(a, b)` | `dateRange(a, b).contains(d)` | [Ranges](/api/ranges/) built into core with `to()`, `for()`, and `overlaps()` |
| `m.fromNow()`, `m.from(other)` | `dt.fromNow()`, `dt.from(other)` | [Relative phrases](/guides/formatting/#relative-phrases) built into core |
| `moment.duration(2, 'h')` | `hours(2)` or `duration('2h')` | Duration helpers in core |
| `m.format('LLL')` | `dt.format('LLL')` | Localized presets from `'LT'` to `'llll'` without locale files |
| `m.format('YYYY-MM-DD HH:mm')` | `dt.format('YYYY-MM-DD HH:mm')` | [Token patterns](/guides/formatting/#token-patterns) |
| `m.isBetween(a, b)` | `dateRange(a, b).contains(d)` | [Ranges](/api/ranges/) with `to()`, `for()`, and `overlaps()` |
| `m.fromNow()`, `m.from(other)` | `dt.fromNow()`, `dt.from(other)` | [Relative phrases](/guides/formatting/#relative-phrases) |
| Non-ISO string parsing | `{ loose: true }` | Load [`@native-dates/plugins/loose`](/plugins/loose/) for locale-aware and informal string parsing |

## Migrating incrementally

Large codebases rarely convert in a single pull request. Call [`toJSDate()`](/api/date-time/#tojsdate) at boundaries that still expect a native JavaScript date, and pass dates straight back into [`datetime()`](/api/datetime-fn/) on the way in.
Large codebases rarely convert in a single pull request. Call [`toJSDate()`](/api/date-time/#tojsdate) at boundaries that still expect a native JavaScript date, and pass dates back into [`datetime()`](/api/datetime-fn/) on the way in.

```js
import { datetime } from 'native-dates';
Expand Down
Loading