Skip to content
Merged
5 changes: 3 additions & 2 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ on:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: pages
Expand All @@ -23,6 +21,9 @@ jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
pages: read
steps:
- name: Checkout
uses: actions/checkout@v7.0.1
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ jobs:
- name: Run linter
run: npm run lint

- name: Run type check
run: npm run ts

- name: Build
run: npm run build

- name: Run tests
run: npm test

Expand Down Expand Up @@ -60,7 +66,7 @@ jobs:
run: npm run test:coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
uses: codecov/codecov-action@v5.5.5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/lcov.info
Expand Down
8 changes: 6 additions & 2 deletions docs/api/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ format(now, 'hh:mm A [GMT]Z');
| `DD` | Day (01-31) | 02, 31 |
| `D` | Day without zero padding | 2, 31 |

`YYYY` prints exactly four digits, so a year above 9999 keeps only its last four: `format(new Date(10000, 0, 1), 'YYYY')` returns `0000`. `Y` prints every digit (`10000`), but `parse()` cannot read either result back; see [Date Range Limitations](./parse#date-range-limitations). The year is counted in the selected [`calendar`](#calendar), so with `'buddhist'` this already happens for dates after December 31, 9456.

### Day of Week Tokens

| Token | Description | Output Examples |
Expand Down Expand Up @@ -232,6 +234,8 @@ format(date, 'MMMM D, YYYY', { calendar: 'buddhist' });
// => August 23, 2568
```

With `'buddhist'`, `YYYY` prints the full year up to Buddhist year 9999, which ends on December 31, 9456 in the Gregorian calendar. Later dates are cut to four digits, as described under [Date Tokens](#date-tokens).

### hour12

**Type**: `"h11" | "h12"`
Expand Down Expand Up @@ -355,8 +359,8 @@ format(date, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]', { timeZone: 'UTC' });
// => 2025-08-23T14:30:45.123Z

// RFC 2822 format
format(date, 'ddd, DD MMM YYYY HH:mm:ss ZZ');
// => Sat, 23 Aug 2025 14:30:45 +09:00
format(date, 'ddd, DD MMM YYYY HH:mm:ss Z');
// => Sat, 23 Aug 2025 14:30:45 +0900

// Log timestamp
format(date, '\\[YYYY-MM-DD HH:mm:ss.SSS\\]');
Expand Down
7 changes: 6 additions & 1 deletion docs/api/parse.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ parse('August 23, 2568', 'MMMM D, YYYY', { calendar: 'buddhist' });
// => Sat Aug 23 2025 00:00:00 GMT-0700
```

For the Buddhist years `parse()` accepts, see [Date Range Limitations](#date-range-limitations).

### hour12

**Type**: `"h11" | "h12"`
Expand Down Expand Up @@ -423,6 +425,8 @@ parse('Jan 1 0000', 'MMM D YYYY');
// => Invalid Date
```

With `calendar: 'buddhist'`, the input year is a Buddhist year, and `YYYY` and `Y` read at most four digits. The parsable range is then `January 1, 0544` to `December 31, 9999` in Buddhist years, which is `January 1, 0001` to `December 31, 9456` in the Gregorian calendar.

### UTC Input Parsing

If the input string doesn't contain a timezone offset and no `timeZone` option is specified, the function treats the input as the local timezone. To parse input as UTC, set `timeZone: 'UTC'` in the options.
Expand Down Expand Up @@ -532,13 +536,14 @@ parse('samedi, 23 août 2025 à 14:30:45', 'dddd, D MMMM YYYY [à] HH:mm:ss', {

```typescript
import { parse } from 'date-and-time';
import { parser as day_of_week } from 'date-and-time/plugins/day-of-week';

// ISO 8601 format
parse('2025-08-23T14:30:45.123Z', 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]', { timeZone: 'UTC' });
// => Sat Aug 23 2025 14:30:45 GMT+0000

// RFC 2822 format
parse('Sat, 23 Aug 2025 14:30:45 +0900', 'ddd, DD MMM YYYY HH:mm:ss ZZ');
parse('Sat, 23 Aug 2025 14:30:45 +0900', 'ddd, DD MMM YYYY HH:mm:ss Z', { plugins: [day_of_week] });
// => Sat Aug 23 2025 14:30:45 GMT+0900

// File naming format
Expand Down
4 changes: 4 additions & 0 deletions docs/api/subtract.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ console.log(parts); // { days: 0, hours: -2, minutes: -15, seconds: 0, ... }
console.log(duration.toDays().format('D[day], H:mm:ss')); // "-0day, 2:15:00"
```

### Sub-millisecond Precision

The millisecond value is rounded to the nearest nanosecond before it is split into units, so a fraction that binary floating point cannot store exactly keeps its last digit: `new Duration(1.001).toMilliseconds().toParts()` returns `{ milliseconds: 1, microseconds: 1, nanoseconds: 0 }`.

## Immutability

Both input Date objects remain unchanged:
Expand Down
Loading
Loading