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.
- package/README.md +44 -63
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,102 +1,83 @@
|
|
|
1
1
|
# daymath
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/daymath)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
42
|
-
- `YYYY-MM-DD` (years 0000–9999)
|
|
43
|
-
- expanded `±YYYYYY-MM-DD` (e.g. `+010000-01-01`)
|
|
26
|
+
## Why
|
|
44
27
|
|
|
45
|
-
**
|
|
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
|
-
|
|
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
|
-
|
|
35
|
+
`Date` **throws** (including `isValid`). `isValid('asdf')` → `false`.
|
|
50
36
|
|
|
51
|
-
## date-fns parity
|
|
37
|
+
## date-fns parity (names, not `Date`)
|
|
52
38
|
|
|
53
39
|
| Topic | daymath |
|
|
54
40
|
|-------|---------|
|
|
55
|
-
|
|
|
56
|
-
| `isSameDay` | Alias of `isEqual`
|
|
57
|
-
| `isValid` |
|
|
58
|
-
| `getMonth` / `setMonth` | **0–11**
|
|
59
|
-
| `getDay` | **0–6**
|
|
60
|
-
| `weekStartsOn` | `0`
|
|
61
|
-
| Intervals | `{ start, end }`
|
|
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
|
|
49
|
+
## API
|
|
65
50
|
|
|
66
|
-
|
|
67
|
-
`parse` · `format` · `isValid`
|
|
51
|
+
**Parse** — `parse` · `format` · `isValid`
|
|
68
52
|
|
|
69
|
-
|
|
70
|
-
`addDays` / `subDays` · `addWeeks` / `subWeeks` · `addMonths` / `subMonths` · `addYears` / `subYears` · `addQuarters` / `subQuarters`
|
|
53
|
+
**Add/sub** — Days · Weeks · Months · Years · Quarters
|
|
71
54
|
|
|
72
|
-
|
|
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
|
-
|
|
77
|
-
`startOfMonth` / `endOfMonth` · `startOfYear` / `endOfYear` · `startOfQuarter` / `endOfQuarter` · `startOfWeek` / `endOfWeek`
|
|
57
|
+
**Bounds** — `startOf`/`endOf` Month · Year · Quarter · Week
|
|
78
58
|
|
|
79
|
-
|
|
80
|
-
`differenceInDays` · `differenceInWeeks` · `differenceInMonths` · `differenceInCalendarMonths` · `differenceInYears` · `differenceInCalendarYears` · `differenceInQuarters` · `differenceInCalendarQuarters`
|
|
59
|
+
**Diffs** — Days · Weeks · Months · CalendarMonths · Years · CalendarYears · Quarters · CalendarQuarters
|
|
81
60
|
|
|
82
|
-
|
|
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
|
-
|
|
86
|
-
`isSunday`…`isSaturday` · `isWeekend` · `isFirstDayOfMonth` · `isLastDayOfMonth`
|
|
63
|
+
**Weekday** — `isSunday`…`isSaturday` · `isWeekend` · first/last day of month
|
|
87
64
|
|
|
88
|
-
|
|
89
|
-
`eachDayOfInterval` · `eachMonthOfInterval` · `eachYearOfInterval` · `isWithinInterval` · `clamp` · `areIntervalsOverlapping`
|
|
65
|
+
**Intervals** — `eachDayOfInterval` · `eachMonthOfInterval` · `eachYearOfInterval` · `isWithinInterval` · `clamp` · `areIntervalsOverlapping`
|
|
90
66
|
|
|
91
|
-
Amounts
|
|
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
|
-
|
|
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.
|
|
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
|
-
"
|
|
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",
|