daymath 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +44 -63
  2. package/package.json +4 -2
package/README.md CHANGED
@@ -1,102 +1,83 @@
1
1
  # daymath
2
2
 
3
- Calendar date math for **ISO 8601** day strings. **date-fns-shaped** names. **Temporal.PlainDate** under the hood.
3
+ [![npm](https://img.shields.io/npm/v/daymath.svg)](https://www.npmjs.com/package/daymath)
4
+ [![license](https://img.shields.io/npm/l/daymath.svg)](./LICENSE)
5
+ [![node](https://img.shields.io/node/v/daymath.svg)](https://www.npmjs.com/package/daymath)
6
+
7
+ **ISO 8601** calendar day math. **date-fns-shaped** names. **Temporal.PlainDate** under the hood.
4
8
 
5
9
  No `Date`. No time zones. No silent “local now.”
6
10
 
11
+ [**Play in the browser →**](https://leemr.github.io/daymath/) · [npm](https://www.npmjs.com/package/daymath) · [FUTURE.md](./FUTURE.md)
12
+
7
13
  ```bash
8
14
  npm install daymath
9
15
  ```
10
16
 
11
- ## Why
12
-
13
- `Date` is a timestamp. Calendar work (“add one month”, “days between hire and start”) is not. This package only does plain calendar days.
14
-
15
- ## Usage
16
-
17
17
  ```js
18
- import {
19
- addDays,
20
- addMonths,
21
- differenceInDays,
22
- isBefore,
23
- isSameDay,
24
- startOfMonth,
25
- eachDayOfInterval,
26
- } from 'daymath'
27
-
28
- addDays('2026-08-06', 1) // '2026-08-07'
29
- addMonths('2026-01-31', 1) // '2026-02-28' (constrain)
18
+ import { addDays, addMonths, differenceInDays, isSameDay } from 'daymath'
19
+
20
+ addDays('2026-08-06', 1) // '2026-08-07'
21
+ addMonths('2026-01-31', 1) // '2026-02-28'
30
22
  differenceInDays('2026-08-06', '2026-08-01') // 5
31
- isBefore('2026-08-05', '2026-08-06') // true
32
- isSameDay('2026-08-06', '2026-08-06') // true (alias of isEqual)
33
- startOfMonth('2026-08-06') // '2026-08-01'
34
- addDays('9999-12-31', 1) // '+010000-01-01' (expanded year)
35
- eachDayOfInterval({
36
- start: '2026-08-05',
37
- end: '2026-08-07',
38
- }) // ['2026-08-05', '2026-08-06', '2026-08-07']
23
+ isSameDay('2026-08-06', '2026-08-06') // true
39
24
  ```
40
25
 
41
- **Inputs:** ISO 8601 day string or `Temporal.PlainDate`.
42
- - `YYYY-MM-DD` (years 0000–9999)
43
- - expanded `±YYYYYY-MM-DD` (e.g. `+010000-01-01`)
26
+ ## Why
44
27
 
45
- **Outputs:** Temporal’s ISO day string (same forms).
28
+ `Date` is a timestamp. Hire dates, passport expiry, trip days are **calendar** values. daymath only does plain days as ISO strings.
46
29
 
47
- `Date` throws (including `isValid(date)`). Bad strings: math helpers throw; `isValid('asdf')` → `false`. Time-bearing / sloppy forms throw.
30
+ | In | Out |
31
+ |----|-----|
32
+ | `YYYY-MM-DD` or expanded `±YYYYYY-MM-DD` | same forms (Temporal `toString`) |
33
+ | or `Temporal.PlainDate` | string |
48
34
 
49
- See [FUTURE.md](./FUTURE.md) for backlog (bundle size, business days, …).
35
+ `Date` **throws** (including `isValid`). `isValid('asdf')` `false`.
50
36
 
51
- ## date-fns parity notes
37
+ ## date-fns parity (names, not `Date`)
52
38
 
53
39
  | Topic | daymath |
54
40
  |-------|---------|
55
- | Value type | ISO day string (not `Date`) |
56
- | `isSameDay` | Alias of `isEqual` (same calendar day) |
57
- | `isValid` | Our predicate: valid day string / PlainDate. `Date` **throws** (not date-fns’s Date check) |
58
- | `getMonth` / `setMonth` | **0–11** like Date/date-fns (0 = January) |
59
- | `getDay` | **0–6** like Date/date-fns (0 = Sunday) |
60
- | `weekStartsOn` | `0` = Sunday … `6` = Saturday (default `0`) |
61
- | Intervals | `{ start, end }` inclusive for `each*` / `isWithin` / `clamp` |
62
- | `areIntervalsOverlapping` | Default `{ inclusive: false }` (date-fns); pass `true` for closed |
41
+ | Values | ISO day **strings**, not `Date` |
42
+ | `isSameDay` | Alias of `isEqual` |
43
+ | `isValid` | Valid daymath day; **`Date` throws** |
44
+ | `getMonth` / `setMonth` | **0–11** (0 = January) |
45
+ | `getDay` | **0–6** (0 = Sunday) |
46
+ | `weekStartsOn` | default `0` (Sunday) |
47
+ | Intervals | `{ start, end }` |
63
48
 
64
- ## API (0.2)
49
+ ## API
65
50
 
66
- ### Parse / format
67
- `parse` · `format` · `isValid`
51
+ **Parse** `parse` · `format` · `isValid`
68
52
 
69
- ### Add / sub
70
- `addDays` / `subDays` · `addWeeks` / `subWeeks` · `addMonths` / `subMonths` · `addYears` / `subYears` · `addQuarters` / `subQuarters`
53
+ **Add/sub** — Days · Weeks · Months · Years · Quarters
71
54
 
72
- ### Get / set
73
- `getYear` · `getMonth` · `getDate` · `getDay` · `getDayOfYear` · `getDaysInMonth` · `getQuarter` · `isLeapYear`
74
- `setYear` · `setMonth` · `setDate`
55
+ **Get/set** — `getYear` · `getMonth` · `getDate` · `getDay` · `getDayOfYear` · `getDaysInMonth` · `getQuarter` · `isLeapYear` · `setYear` · `setMonth` · `setDate`
75
56
 
76
- ### Start / end
77
- `startOfMonth` / `endOfMonth` · `startOfYear` / `endOfYear` · `startOfQuarter` / `endOfQuarter` · `startOfWeek` / `endOfWeek`
57
+ **Bounds** `startOf`/`endOf` Month · Year · Quarter · Week
78
58
 
79
- ### Differences
80
- `differenceInDays` · `differenceInWeeks` · `differenceInMonths` · `differenceInCalendarMonths` · `differenceInYears` · `differenceInCalendarYears` · `differenceInQuarters` · `differenceInCalendarQuarters`
59
+ **Diffs** — Days · Weeks · Months · CalendarMonths · Years · CalendarYears · Quarters · CalendarQuarters
81
60
 
82
- ### Compare
83
- `isBefore` · `isAfter` · `isEqual` · `isSameDay` · `isSameWeek` · `isSameMonth` · `isSameYear` · `isSameQuarter` · `compareAsc` · `compareDesc` · `min` · `max`
61
+ **Compare** — `isBefore` · `isAfter` · `isEqual` · `isSameDay` · `isSameWeek` · Month · Year · Quarter · `compareAsc` · `compareDesc` · `min` · `max`
84
62
 
85
- ### Weekday / month edges
86
- `isSunday`…`isSaturday` · `isWeekend` · `isFirstDayOfMonth` · `isLastDayOfMonth`
63
+ **Weekday** — `isSunday`…`isSaturday` · `isWeekend` · first/last day of month
87
64
 
88
- ### Intervals
89
- `eachDayOfInterval` · `eachMonthOfInterval` · `eachYearOfInterval` · `isWithinInterval` · `clamp` · `areIntervalsOverlapping`
65
+ **Intervals** — `eachDayOfInterval` · `eachMonthOfInterval` · `eachYearOfInterval` · `isWithinInterval` · `clamp` · `areIntervalsOverlapping`
90
66
 
91
- Amounts must be finite integers.
67
+ Amounts are finite integers.
92
68
 
93
69
  ## Temporal
94
70
 
95
71
  Uses global `Temporal` when present; otherwise [`temporal-polyfill`](https://www.npmjs.com/package/temporal-polyfill).
96
72
 
97
- ## Types
73
+ ## Types & tests
74
+
75
+ Plain JS + `index.d.ts` (no compile step).
98
76
 
99
- Ships `index.d.ts` (no TypeScript compile step). Source is plain JS.
77
+ ```bash
78
+ npm test
79
+ npm run test:coverage # 100% lines on index.js
80
+ ```
100
81
 
101
82
  ## License
102
83
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "daymath",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Calendar date math (ISO 8601 day / PlainDate). date-fns-shaped. No time zones.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -18,8 +18,10 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "test": "node --test test.js",
21
- "prepublishOnly": "npm test"
21
+ "test:coverage": "node --test --experimental-test-coverage --test-coverage-include=index.js test.js",
22
+ "prepublishOnly": "npm run test:coverage"
22
23
  },
24
+
23
25
  "keywords": [
24
26
  "date",
25
27
  "calendar",