temporal-fmt 0.9.3 → 0.9.31
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 +2 -0
- package/dist/calendarUtils.cjs +259 -4
- package/dist/calendarUtils.cjs.map +1 -1
- package/dist/calendarUtils.js +33 -1
- package/dist/chunk-4N3WCGEY.js +183 -0
- package/dist/{chunk-SSPABEUR.js.map → chunk-4N3WCGEY.js.map} +1 -1
- package/dist/chunk-5UTV5VP6.js +984 -0
- package/dist/chunk-5UTV5VP6.js.map +1 -0
- package/dist/chunk-ACKKWH5Z.js +578 -0
- package/dist/{chunk-2JHEV7ZF.js.map → chunk-ACKKWH5Z.js.map} +1 -1
- package/dist/chunk-DR62Z6GV.js +224 -0
- package/dist/{chunk-ZGMTY52O.js.map → chunk-DR62Z6GV.js.map} +1 -1
- package/dist/chunk-EGUUO6LE.js +439 -0
- package/dist/chunk-EGUUO6LE.js.map +1 -0
- package/dist/chunk-GPB4JHGI.js +65 -0
- package/dist/chunk-GPB4JHGI.js.map +1 -0
- package/dist/chunk-H7YQX25T.js +170 -0
- package/dist/{chunk-J2AQNXF2.js.map → chunk-H7YQX25T.js.map} +1 -1
- package/dist/chunk-HXY2GUUM.js +182 -0
- package/dist/{chunk-EHLRZULM.js.map → chunk-HXY2GUUM.js.map} +1 -1
- package/dist/chunk-L24NPTAJ.js +328 -0
- package/dist/{chunk-GMGZZG6I.js.map → chunk-L24NPTAJ.js.map} +1 -1
- package/dist/chunk-M3GDTHMT.js +169 -0
- package/dist/chunk-M3GDTHMT.js.map +1 -0
- package/dist/chunk-MKPDLQKD.js +51 -0
- package/dist/chunk-MKPDLQKD.js.map +1 -0
- package/dist/chunk-P3G4JRYC.js +205 -0
- package/dist/{chunk-4XRE37WT.js.map → chunk-P3G4JRYC.js.map} +1 -1
- package/dist/chunk-RIZ3HN37.js +181 -0
- package/dist/{chunk-UJR6DHXY.js.map → chunk-RIZ3HN37.js.map} +1 -1
- package/dist/chunk-TSLPIURC.js +242 -0
- package/dist/{chunk-VQXUMFB2.js.map → chunk-TSLPIURC.js.map} +1 -1
- package/dist/chunk-UOPAV3WX.js +75 -0
- package/dist/chunk-UOPAV3WX.js.map +1 -0
- package/dist/chunk-YEUASGDK.js +9 -0
- package/dist/chunk-YEUASGDK.js.map +1 -0
- package/dist/chunk-ZQZF5EXW.js +29 -0
- package/dist/chunk-ZQZF5EXW.js.map +1 -0
- package/dist/duration.cjs +638 -26
- package/dist/duration.cjs.map +1 -1
- package/dist/duration.js +28 -1
- package/dist/format.cjs +833 -35
- package/dist/format.cjs.map +1 -1
- package/dist/format.js +20 -1
- package/dist/index.cjs +6905 -163
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3091 -58
- package/dist/index.js.map +1 -1
- package/dist/interval.cjs +1015 -35
- package/dist/interval.cjs.map +1 -1
- package/dist/interval.js +41 -1
- package/dist/localeRegistry.cjs +375 -32
- package/dist/localeRegistry.cjs.map +1 -1
- package/dist/localeRegistry.js +11 -1
- package/dist/parse.cjs +1797 -70
- package/dist/parse.cjs.map +1 -1
- package/dist/parse.js +20 -1
- package/dist/recurrence.cjs +452 -20
- package/dist/recurrence.cjs.map +1 -1
- package/dist/recurrence.js +20 -1
- package/dist/relativeTime.cjs +268 -21
- package/dist/relativeTime.cjs.map +1 -1
- package/dist/relativeTime.js +14 -1
- package/dist/timezone.cjs +387 -20
- package/dist/timezone.cjs.map +1 -1
- package/dist/timezone.js +26 -1
- package/package.json +3 -5
- package/scripts/cli.mjs +17 -5
- package/dist/chunk-2JHEV7ZF.js +0 -7
- package/dist/chunk-3MZLTVP3.js +0 -2
- package/dist/chunk-3MZLTVP3.js.map +0 -1
- package/dist/chunk-4JDAJSEM.js +0 -35
- package/dist/chunk-4JDAJSEM.js.map +0 -1
- package/dist/chunk-4XRE37WT.js +0 -2
- package/dist/chunk-5U5WJ465.js +0 -36
- package/dist/chunk-5U5WJ465.js.map +0 -1
- package/dist/chunk-C6ZZ62ET.js +0 -2
- package/dist/chunk-C6ZZ62ET.js.map +0 -1
- package/dist/chunk-EHLRZULM.js +0 -5
- package/dist/chunk-GMGZZG6I.js +0 -2
- package/dist/chunk-J2AQNXF2.js +0 -2
- package/dist/chunk-NPKJ7QFK.js +0 -7
- package/dist/chunk-NPKJ7QFK.js.map +0 -1
- package/dist/chunk-R4YEFOVE.js +0 -2
- package/dist/chunk-R4YEFOVE.js.map +0 -1
- package/dist/chunk-SSPABEUR.js +0 -11
- package/dist/chunk-UJR6DHXY.js +0 -2
- package/dist/chunk-VQXUMFB2.js +0 -21
- package/dist/chunk-XH46JNPK.js +0 -2
- package/dist/chunk-XH46JNPK.js.map +0 -1
- package/dist/chunk-ZGMTY52O.js +0 -2
package/README.md
CHANGED
|
@@ -836,6 +836,8 @@ A handful of functions exist specifically to feed editor tooling — autocomplet
|
|
|
836
836
|
|
|
837
837
|
The CLI ships in this package (`scripts/cli.mjs`) and reads/writes stdin/stdout. Run it via `npm run cli` inside a checkout of this repo, or `node scripts/cli.mjs` directly. Called with a subcommand it runs once and exits, same as any Unix tool — fine for scripts and CI:
|
|
838
838
|
|
|
839
|
+
On Node 26+ the CLI uses native `Temporal` and needs nothing extra. Below that, it looks for a globally-installed [`temporal-polyfill`](https://github.com/fullcalendar/temporal-polyfill) and exits with an install hint if it can't find one — `temporal-fmt` itself ships with zero dependencies, so this one's on you: `npm install temporal-polyfill`.
|
|
840
|
+
|
|
839
841
|
```sh
|
|
840
842
|
temporal-fmt format "2026-08-04T15:45:30" "yyyy-MM-dd HH:mm:ss"
|
|
841
843
|
temporal-fmt parse "yyyy-MM-dd" "2026-08-04"
|
package/dist/calendarUtils.cjs
CHANGED
|
@@ -1,5 +1,260 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/calendarUtils.ts
|
|
21
|
+
var calendarUtils_exports = {};
|
|
22
|
+
__export(calendarUtils_exports, {
|
|
23
|
+
asDateFieldView: () => asDateFieldView,
|
|
24
|
+
dayOfYearHelper: () => dayOfYearHelper,
|
|
25
|
+
daysInMonth: () => daysInMonth,
|
|
26
|
+
daysInYear: () => daysInYear2,
|
|
27
|
+
endOf: () => endOf,
|
|
28
|
+
getMonth: () => getMonth,
|
|
29
|
+
getQuarter: () => getQuarter,
|
|
30
|
+
getWeekday: () => getWeekday,
|
|
31
|
+
isLeapMonth: () => isLeapMonth,
|
|
32
|
+
isLeapYear: () => isLeapYear,
|
|
33
|
+
monthsInYear: () => monthsInYear,
|
|
34
|
+
startOf: () => startOf,
|
|
35
|
+
weekOfYear: () => weekOfYear,
|
|
36
|
+
weekYear: () => weekYear
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(calendarUtils_exports);
|
|
39
|
+
|
|
40
|
+
// src/isoWeek.ts
|
|
41
|
+
var CUMULATIVE_DAYS_BY_MONTH = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
|
|
42
|
+
function isGregorianLeapYear(year) {
|
|
43
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
44
|
+
}
|
|
45
|
+
function daysInYear(year) {
|
|
46
|
+
return isGregorianLeapYear(year) ? 366 : 365;
|
|
47
|
+
}
|
|
48
|
+
function dayOfYear(year, month, day) {
|
|
49
|
+
let doy = CUMULATIVE_DAYS_BY_MONTH[month - 1] + day;
|
|
50
|
+
if (month > 2 && isGregorianLeapYear(year)) doy += 1;
|
|
51
|
+
return doy;
|
|
52
|
+
}
|
|
53
|
+
var REFERENCE_YEAR = 2e3;
|
|
54
|
+
function dayOfWeekOfJan1(year) {
|
|
55
|
+
let offset = 0;
|
|
56
|
+
if (year >= REFERENCE_YEAR) {
|
|
57
|
+
for (let y = REFERENCE_YEAR; y < year; y++) offset += daysInYear(y);
|
|
58
|
+
} else {
|
|
59
|
+
for (let y = year; y < REFERENCE_YEAR; y++) offset -= daysInYear(y);
|
|
60
|
+
}
|
|
61
|
+
const zeroIndexed = ((6 - 1 + offset) % 7 + 7) % 7;
|
|
62
|
+
return zeroIndexed + 1;
|
|
63
|
+
}
|
|
64
|
+
function isoWeekYearAndWeek(year, month, day, dayOfWeek) {
|
|
65
|
+
const doy = dayOfYear(year, month, day);
|
|
66
|
+
const thursdayDoyRelative = doy + (4 - dayOfWeek);
|
|
67
|
+
let isoYear;
|
|
68
|
+
let thursdayDoy;
|
|
69
|
+
if (thursdayDoyRelative < 1) {
|
|
70
|
+
isoYear = year - 1;
|
|
71
|
+
thursdayDoy = thursdayDoyRelative + daysInYear(isoYear);
|
|
72
|
+
} else if (thursdayDoyRelative > daysInYear(year)) {
|
|
73
|
+
isoYear = year + 1;
|
|
74
|
+
thursdayDoy = thursdayDoyRelative - daysInYear(year);
|
|
75
|
+
} else {
|
|
76
|
+
isoYear = year;
|
|
77
|
+
thursdayDoy = thursdayDoyRelative;
|
|
78
|
+
}
|
|
79
|
+
const jan1Dow = dayOfWeekOfJan1(isoYear);
|
|
80
|
+
const firstThursdayDoy = 1 + (4 - jan1Dow + 7) % 7;
|
|
81
|
+
const week = 1 + Math.floor((thursdayDoy - firstThursdayDoy) / 7);
|
|
82
|
+
return { isoYear, week };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/calendarUtils.ts
|
|
86
|
+
function requireFields(view, fields) {
|
|
87
|
+
for (const f of fields) {
|
|
88
|
+
if (typeof view[f] !== "number") {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`temporal-fmt: calendar helper requires "${String(f)}", which this value doesn't have. Pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function daysInMonth(view) {
|
|
96
|
+
requireFields(view, ["year", "month"]);
|
|
97
|
+
const { year, month } = view;
|
|
98
|
+
const LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
99
|
+
if (month === 2 && isGregorianLeapYear(year)) return 29;
|
|
100
|
+
return LENGTHS[month - 1];
|
|
101
|
+
}
|
|
102
|
+
function daysInYear2(view) {
|
|
103
|
+
requireFields(view, ["year"]);
|
|
104
|
+
return isGregorianLeapYear(view.year) ? 366 : 365;
|
|
105
|
+
}
|
|
106
|
+
function monthsInYear(_view) {
|
|
107
|
+
return 12;
|
|
108
|
+
}
|
|
109
|
+
function isLeapYear(view) {
|
|
110
|
+
requireFields(view, ["year"]);
|
|
111
|
+
return isGregorianLeapYear(view.year);
|
|
112
|
+
}
|
|
113
|
+
function isLeapMonth(_view) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
function dayOfYearHelper(view) {
|
|
117
|
+
requireFields(view, ["year", "month", "day"]);
|
|
118
|
+
return dayOfYear(view.year, view.month, view.day);
|
|
119
|
+
}
|
|
120
|
+
function weekOfYear(view) {
|
|
121
|
+
requireFields(view, ["year", "month", "day", "dayOfWeek"]);
|
|
122
|
+
return isoWeekYearAndWeek(view.year, view.month, view.day, view.dayOfWeek).week;
|
|
123
|
+
}
|
|
124
|
+
function weekYear(view) {
|
|
125
|
+
requireFields(view, ["year", "month", "day", "dayOfWeek"]);
|
|
126
|
+
return isoWeekYearAndWeek(view.year, view.month, view.day, view.dayOfWeek).isoYear;
|
|
127
|
+
}
|
|
128
|
+
function validateStartMonth(startMonth) {
|
|
129
|
+
if (!Number.isInteger(startMonth) || startMonth < 1 || startMonth > 12) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
`temporal-fmt: getQuarter's startMonth must be an integer from 1 to 12 (got ${startMonth}).`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function getQuarter(view, options = {}) {
|
|
136
|
+
requireFields(view, ["month"]);
|
|
137
|
+
const startMonth = options.startMonth ?? 1;
|
|
138
|
+
validateStartMonth(startMonth);
|
|
139
|
+
if (startMonth === 1) {
|
|
140
|
+
return Math.ceil(view.month / 3);
|
|
141
|
+
}
|
|
142
|
+
const shifted = (view.month - startMonth + 12) % 12 + 1;
|
|
143
|
+
return Math.ceil(shifted / 3);
|
|
144
|
+
}
|
|
145
|
+
function getMonth(view) {
|
|
146
|
+
requireFields(view, ["month"]);
|
|
147
|
+
return view.month;
|
|
148
|
+
}
|
|
149
|
+
function getWeekday(view) {
|
|
150
|
+
requireFields(view, ["dayOfWeek"]);
|
|
151
|
+
return view.dayOfWeek;
|
|
152
|
+
}
|
|
153
|
+
function touchesTime(unit) {
|
|
154
|
+
return unit === "day" || unit === "month" || unit === "year";
|
|
155
|
+
}
|
|
156
|
+
function recomputeDayOfWeek(view) {
|
|
157
|
+
if (typeof view.dayOfWeek !== "number") return;
|
|
158
|
+
/* c8 ignore start @preserve -- unreachable: startOf()/endOf() both call
|
|
159
|
+
* asDateFieldView() before this, which already throws if year/month/day
|
|
160
|
+
* aren't all numbers — so by the time a value with a numeric dayOfWeek
|
|
161
|
+
* reaches here, year/month/day are guaranteed present too. */
|
|
162
|
+
if (typeof view.year !== "number" || typeof view.month !== "number" || typeof view.day !== "number") return;
|
|
163
|
+
/* c8 ignore stop @preserve */
|
|
164
|
+
const jsDow = new Date(Date.UTC(view.year, view.month - 1, view.day)).getUTCDay();
|
|
165
|
+
view.dayOfWeek = jsDow === 0 ? 7 : jsDow;
|
|
166
|
+
}
|
|
167
|
+
function startOf(value, unit) {
|
|
168
|
+
const view = asDateFieldView(value);
|
|
169
|
+
const result = { ...view };
|
|
170
|
+
if (unit === "year") {
|
|
171
|
+
result.month = 1;
|
|
172
|
+
result.day = 1;
|
|
173
|
+
} else if (unit === "month") {
|
|
174
|
+
result.day = 1;
|
|
175
|
+
}
|
|
176
|
+
recomputeDayOfWeek(result);
|
|
177
|
+
if (touchesTime(unit)) {
|
|
178
|
+
result.hour = 0;
|
|
179
|
+
result.minute = 0;
|
|
180
|
+
result.second = 0;
|
|
181
|
+
result.millisecond = 0;
|
|
182
|
+
} else if (unit === "hour") {
|
|
183
|
+
result.minute = 0;
|
|
184
|
+
result.second = 0;
|
|
185
|
+
result.millisecond = 0;
|
|
186
|
+
} else if (unit === "minute") {
|
|
187
|
+
result.second = 0;
|
|
188
|
+
result.millisecond = 0;
|
|
189
|
+
} else if (unit === "second") {
|
|
190
|
+
result.millisecond = 0;
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
function endOf(value, unit) {
|
|
195
|
+
const view = asDateFieldView(value);
|
|
196
|
+
const result = { ...view };
|
|
197
|
+
if (unit === "year") {
|
|
198
|
+
result.month = 12;
|
|
199
|
+
result.day = daysInMonth({ year: result.year, month: 12 });
|
|
200
|
+
} else if (unit === "month") {
|
|
201
|
+
result.day = daysInMonth({ year: result.year, month: result.month });
|
|
202
|
+
}
|
|
203
|
+
recomputeDayOfWeek(result);
|
|
204
|
+
if (touchesTime(unit)) {
|
|
205
|
+
result.hour = 23;
|
|
206
|
+
result.minute = 59;
|
|
207
|
+
result.second = 59;
|
|
208
|
+
result.millisecond = 999;
|
|
209
|
+
} else if (unit === "hour") {
|
|
210
|
+
result.minute = 59;
|
|
211
|
+
result.second = 59;
|
|
212
|
+
result.millisecond = 999;
|
|
213
|
+
} else if (unit === "minute") {
|
|
214
|
+
result.second = 59;
|
|
215
|
+
result.millisecond = 999;
|
|
216
|
+
} else if (unit === "second") {
|
|
217
|
+
result.millisecond = 999;
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
function asDateFieldView(value) {
|
|
222
|
+
if (typeof value !== "object" || value === null) {
|
|
223
|
+
throw new Error(`temporal-fmt: expected a date-carrying Temporal value, got ${String(value)}.`);
|
|
224
|
+
}
|
|
225
|
+
const v = value;
|
|
226
|
+
const out = {};
|
|
227
|
+
if (typeof v.year === "number") out.year = v.year;
|
|
228
|
+
if (typeof v.month === "number") out.month = v.month;
|
|
229
|
+
if (typeof v.day === "number") out.day = v.day;
|
|
230
|
+
if (typeof v.hour === "number") out.hour = v.hour;
|
|
231
|
+
if (typeof v.minute === "number") out.minute = v.minute;
|
|
232
|
+
if (typeof v.second === "number") out.second = v.second;
|
|
233
|
+
if (typeof v.millisecond === "number") out.millisecond = v.millisecond;
|
|
234
|
+
if (typeof v.dayOfWeek === "number") out.dayOfWeek = v.dayOfWeek;
|
|
235
|
+
if (typeof v.calendarId === "string") out.calendarId = v.calendarId;
|
|
236
|
+
if (out.year === void 0 || out.month === void 0 || out.day === void 0) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
`temporal-fmt: value is missing year/month/day fields \u2014 pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
244
|
+
0 && (module.exports = {
|
|
245
|
+
asDateFieldView,
|
|
246
|
+
dayOfYearHelper,
|
|
247
|
+
daysInMonth,
|
|
248
|
+
daysInYear,
|
|
249
|
+
endOf,
|
|
250
|
+
getMonth,
|
|
251
|
+
getQuarter,
|
|
252
|
+
getWeekday,
|
|
253
|
+
isLeapMonth,
|
|
254
|
+
isLeapYear,
|
|
255
|
+
monthsInYear,
|
|
256
|
+
startOf,
|
|
257
|
+
weekOfYear,
|
|
258
|
+
weekYear
|
|
259
|
+
});
|
|
5
260
|
//# sourceMappingURL=calendarUtils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/calendarUtils.ts","../src/isoWeek.ts"],"sourcesContent":["// Calendar utility helpers. These are pure functions\n// over the TemporalLike shape — no Temporal namespace needed, same\n// approach as isoWeek.ts and the field-reading helpers in format.ts.\n// Letting callers compute dayOfYear/weekOfYear/etc. without going\n// through format() means they can build their own derived values\n// without committing to a string format.\n//\n// Calendar-sensitivity: the helpers in this module assume the\n// iso8601 (Gregorian) calendar — that's what TemporalLike fields\n// carry for the overwhelming majority of callers. Non-Gregorian\n// calendars (hebrew, islamic, etc.) need their own helpers; this\n// module doesn't try to be calendar-polymorphic the way Temporal\n// itself is. Documented limitation, not a design choice — see\n// VERIFICATION.md for the rationale.\n\nimport { isGregorianLeapYear, dayOfYear, isoWeekYearAndWeek } from './isoWeek.js';\n\n// A subset of TemporalLike that has the date fields these helpers need,\n// plus optional time fields. PlainTime isn't a DateFieldView (no\n// year/month/day), but PlainDateTime / ZonedDateTime / PlainDate all\n// match. Time fields are optional so callers can pass a PlainDate\n// to startOf(value, 'month') without having to populate hour/minute/etc.\n// Exported so the comparison/arithmetic modules can use the same\n// narrowing.\nexport interface DateFieldView {\n year?: number;\n month?: number;\n day?: number;\n hour?: number;\n minute?: number;\n second?: number;\n millisecond?: number;\n dayOfWeek?: number;\n calendarId?: string;\n}\n\nfunction requireFields(view: DateFieldView, fields: Array<keyof DateFieldView>): void {\n for (const f of fields) {\n if (typeof view[f] !== 'number') {\n throw new Error(\n `temporal-fmt: calendar helper requires \"${String(f)}\", which this value doesn't have. ` +\n `Pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`\n );\n }\n }\n}\n\nexport function daysInMonth(view: DateFieldView): number {\n requireFields(view, ['year', 'month']);\n const { year, month } = view;\n // Standard Gregorian month lengths. February's length depends on\n // whether `year` is a leap year — the same isGregorianLeapYear check\n // isoWeek.ts uses for dayOfYear arithmetic.\n const LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n if (month === 2 && isGregorianLeapYear(year!)) return 29;\n return LENGTHS[(month! - 1)!]!;\n}\n\nexport function daysInYear(view: DateFieldView): 365 | 366 {\n requireFields(view, ['year']);\n return isGregorianLeapYear(view.year!) ? 366 : 365;\n}\n\nexport function monthsInYear(_view: DateFieldView): 12 {\n // Gregorian always has 12 months. Other calendars (Hebrew leap years\n // have 13) need calendar-aware logic this module doesn't carry — see\n // the file-level comment. The `_view` parameter is kept so the\n // signature mirrors the other helpers and a future calendar-aware\n // implementation can use it without changing call sites.\n return 12;\n}\n\nexport function isLeapYear(view: DateFieldView): boolean {\n requireFields(view, ['year']);\n return isGregorianLeapYear(view.year!);\n}\n\n// `isLeapMonth` would require knowing which month of a leap-year-aware\n// calendar is the leap month — Gregorian doesn't have one, so this\n// returns false unconditionally. Kept here so the public surface\n// matches the module's listing; non-Gregorian calendars need\n// a different implementation.\nexport function isLeapMonth(_view: DateFieldView): boolean {\n return false;\n}\n\nexport function dayOfYearHelper(view: DateFieldView): number {\n requireFields(view, ['year', 'month', 'day']);\n return dayOfYear(view.year!, view.month!, view.day!);\n}\n\n// ISO 8601 week and week-year. Delegates to isoWeek.ts's\n// isoWeekYearAndWeek, which does the full Thursday-of-week\n// computation to handle the year-boundary cases (Dec 29-31 belonging\n// to week 1 of next year, Jan 1-3 belonging to week 52/53 of the\n// previous year).\nexport function weekOfYear(view: DateFieldView): number {\n requireFields(view, ['year', 'month', 'day', 'dayOfWeek']);\n return isoWeekYearAndWeek(view.year!, view.month!, view.day!, view.dayOfWeek!).week;\n}\n\nexport function weekYear(view: DateFieldView): number {\n requireFields(view, ['year', 'month', 'day', 'dayOfWeek']);\n return isoWeekYearAndWeek(view.year!, view.month!, view.day!, view.dayOfWeek!).isoYear;\n}\n\n/**\n * Fiscal-quarter options. `startMonth` is the calendar month (1-12) the\n * fiscal year begins on — e.g. `7` for a fiscal year starting in July.\n * Omitted or `1` gives the calendar-quarter behavior getQuarter() has\n * always had (Jan-Mar = Q1, etc.), so existing callers passing nothing\n * see no change.\n */\nexport interface QuarterOptions {\n startMonth?: number;\n}\n\nfunction validateStartMonth(startMonth: number): void {\n if (!Number.isInteger(startMonth) || startMonth < 1 || startMonth > 12) {\n throw new Error(\n `temporal-fmt: getQuarter's startMonth must be an integer from 1 to 12 (got ${startMonth}).`\n );\n }\n}\n\nexport function getQuarter(view: DateFieldView, options: QuarterOptions = {}): number {\n requireFields(view, ['month']);\n const startMonth = options.startMonth ?? 1;\n validateStartMonth(startMonth);\n if (startMonth === 1) {\n // Mirrors the Q token: months 1-3 → Q1, 4-6 → Q2, 7-9 → Q3, 10-12 → Q4.\n return Math.ceil(view.month! / 3);\n }\n // Fiscal case: shift the month so startMonth becomes month 1 of the\n // fiscal year (mod 12, 1-indexed), then apply the same ceil(/3) rule.\n // E.g. startMonth=7 (fiscal year starts July): July→1, Aug→2, ...,\n // Dec→6, Jan→7, ..., June→12. Then Q1 = fiscal months 1-3 (Jul-Sep),\n // matching the common \"FY starts in July\" convention where Q1 is the\n // first quarter of the fiscal year, not a quarter numbered by which\n // calendar quarter it falls in.\n const shifted = ((view.month! - startMonth + 12) % 12) + 1;\n return Math.ceil(shifted / 3);\n}\n\n// `getMonth` / `getWeekday` look trivial (just read the field) but\n// they're kept as real functions for API surface consistency with the\n// rest of this module. They also normalize: getWeekday returns 1-7\n// (Mon-Sun, matching Temporal's spec) regardless of what numbering the\n// caller's underlying value uses.\nexport function getMonth(view: DateFieldView): number {\n requireFields(view, ['month']);\n return view.month!;\n}\n\nexport function getWeekday(view: DateFieldView): number {\n requireFields(view, ['dayOfWeek']);\n return view.dayOfWeek!;\n}\n\n// startOf / endOf return new field bags (not Temporal objects — this\n// module is polyfill-free) with the relevant fields zeroed/extended.\n// Callers can pass the result to a Temporal constructor if they want\n// a typed value.\nexport type StartOfUnit = 'day' | 'month' | 'year' | 'hour' | 'minute' | 'second';\n\n// Returns true if the given unit (when used with startOf/endOf) should\n// also touch the time fields. 'day', 'month', 'year' all imply a\n// resolution coarser than an hour, so startOf zeroes the time fields\n// and endOf maxes them. Sub-hour units (hour/minute/second) only touch\n// the fields finer than themselves.\nfunction touchesTime(unit: StartOfUnit): boolean {\n return unit === 'day' || unit === 'month' || unit === 'year';\n}\n\n// startOf/endOf reassign year/month/day, which invalidates any\n// dayOfWeek carried over from the input — a plain { ...view } spread\n// leaves the old value sitting there unchanged. Same failure mode\n// businessCalendar.ts's isBusinessDay() works around for add(); we\n// recompute here rather than trust the copied field.\nfunction recomputeDayOfWeek(view: DateFieldView): void {\n if (typeof view.dayOfWeek !== 'number') return;\n /* c8 ignore start @preserve -- unreachable: startOf()/endOf() both call\n * asDateFieldView() before this, which already throws if year/month/day\n * aren't all numbers — so by the time a value with a numeric dayOfWeek\n * reaches here, year/month/day are guaranteed present too. */\n if (typeof view.year !== 'number' || typeof view.month !== 'number' || typeof view.day !== 'number') return;\n /* c8 ignore stop @preserve */\n const jsDow = new Date(Date.UTC(view.year, view.month - 1, view.day)).getUTCDay(); // 0=Sun..6=Sat\n view.dayOfWeek = jsDow === 0 ? 7 : jsDow; // 1=Mon..7=Sun\n}\n\nexport function startOf(value: unknown, unit: StartOfUnit): DateFieldView {\n const view = asDateFieldView(value);\n const result: DateFieldView = { ...view };\n if (unit === 'year') {\n result.month = 1;\n result.day = 1;\n } else if (unit === 'month') {\n result.day = 1;\n }\n recomputeDayOfWeek(result);\n if (touchesTime(unit)) {\n result.hour = 0;\n result.minute = 0;\n result.second = 0;\n result.millisecond = 0;\n } else if (unit === 'hour') {\n result.minute = 0;\n result.second = 0;\n result.millisecond = 0;\n } else if (unit === 'minute') {\n result.second = 0;\n result.millisecond = 0;\n } else if (unit === 'second') {\n result.millisecond = 0;\n }\n return result;\n}\n\nexport function endOf(value: unknown, unit: StartOfUnit): DateFieldView {\n const view = asDateFieldView(value);\n const result: DateFieldView = { ...view };\n if (unit === 'year') {\n result.month = 12;\n result.day = daysInMonth({ year: result.year!, month: 12 });\n } else if (unit === 'month') {\n result.day = daysInMonth({ year: result.year!, month: result.month! });\n }\n recomputeDayOfWeek(result);\n if (touchesTime(unit)) {\n result.hour = 23;\n result.minute = 59;\n result.second = 59;\n result.millisecond = 999;\n } else if (unit === 'hour') {\n result.minute = 59;\n result.second = 59;\n result.millisecond = 999;\n } else if (unit === 'minute') {\n result.second = 59;\n result.millisecond = 999;\n } else if (unit === 'second') {\n result.millisecond = 999;\n }\n return result;\n}\n\n// Type-narrowing helpers used by the comparison/arithmetic modules.\n// Lets them accept any of the four date-carrying Temporal types without\n// importing Temporal itself.\nexport function asDateFieldView(value: unknown): DateFieldView {\n if (typeof value !== 'object' || value === null) {\n throw new Error(`temporal-fmt: expected a date-carrying Temporal value, got ${String(value)}.`);\n }\n // Temporal instances expose year/month/day/etc. as prototype getters,\n // not own enumerable properties — so `{ ...value }` would lose them.\n // Read them explicitly. Only the fields actually present on this\n // value type end up in the returned view.\n const v = value as Record<string, unknown>;\n const out: DateFieldView = {};\n if (typeof v.year === 'number') out.year = v.year;\n if (typeof v.month === 'number') out.month = v.month;\n if (typeof v.day === 'number') out.day = v.day;\n if (typeof v.hour === 'number') out.hour = v.hour;\n if (typeof v.minute === 'number') out.minute = v.minute;\n if (typeof v.second === 'number') out.second = v.second;\n if (typeof v.millisecond === 'number') out.millisecond = v.millisecond;\n if (typeof v.dayOfWeek === 'number') out.dayOfWeek = v.dayOfWeek;\n if (typeof v.calendarId === 'string') out.calendarId = v.calendarId;\n if (out.year === undefined || out.month === undefined || out.day === undefined) {\n throw new Error(\n `temporal-fmt: value is missing year/month/day fields — pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`\n );\n }\n return out;\n}\n\n// Re-export the TemporalType alias so callers can import everything\n// from one place.\nexport type { TemporalType } from './tokenMetadata.js';\n// Re-export TemporalLike for the same reason.\nexport type { TemporalLike } from './tokens.js';","// ISO 8601 week numbering: a week runs Monday–Sunday, and week 1 of a year\n// is the week containing the year's first Thursday (equivalently, the week\n// containing January 4). This means late-December dates can fall in week 1\n// of the *next* year, and early-January dates can fall in week 52 or 53 of\n// the *previous* year. The \"ISO week-numbering year\" (what `RRRR` formats)\n// is that adjacent year, not the calendar year.\n//\n// Computed here from the date's own year/month/day plus its ISO dayOfWeek\n// (1=Mon..7=Sun, matching Temporal's numbering) using plain Gregorian\n// arithmetic — no Temporal factory needed. format() only has the fields\n// the caller already put on the object, and requiring a Temporal\n// implementation just for ISO week would be a regression for callers who\n// use format() without setTemporal() on a non-26 Node.\n\nconst DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\nconst CUMULATIVE_DAYS_BY_MONTH = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];\n\nexport function isGregorianLeapYear(year: number): boolean {\n // Gregorian rule: divisible by 4, except centuries which must also be\n // divisible by 400. Temporal's iso8601 calendar is proleptic Gregorian\n // (no Julian cutover), so this applies for every year, including BCE.\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\n\nfunction daysInYear(year: number): 365 | 366 {\n return isGregorianLeapYear(year) ? 366 : 365;\n}\n\nexport function dayOfYear(year: number, month: number, day: number): number {\n let doy = CUMULATIVE_DAYS_BY_MONTH[month - 1]! + day;\n if (month > 2 && isGregorianLeapYear(year)) doy += 1;\n return doy;\n}\n\n// Jan 1, 2000 was a Saturday — ISO dayOfWeek 6. Anchoring day-of-week\n// computations to a known reference date is simpler and cheaper than\n// pulling in Zeller's congruence, and the reference never changes.\nconst REFERENCE_YEAR = 2000;\nconst REFERENCE_JAN1_DAY_OF_WEEK = 6;\n\nfunction dayOfWeekOfJan1(year: number): number {\n // Sum full-year deltas from the 2000 anchor rather than recomputing from\n // scratch each call — the per-call work is a single mod this way, and\n // the loop rarely runs far (a typical caller passes a current-era year).\n let offset = 0;\n if (year >= REFERENCE_YEAR) {\n for (let y = REFERENCE_YEAR; y < year; y++) offset += daysInYear(y);\n } else {\n for (let y = year; y < REFERENCE_YEAR; y++) offset -= daysInYear(y);\n }\n // Convert \"days since Jan 1, 2000\" into an ISO day-of-week (1=Mon..7=Sun).\n // Jan 1, 2000 was ISO 6 (Sat), so zero-indexed dow = (6-1 + offset) mod 7.\n const zeroIndexed = (((6 - 1 + offset) % 7) + 7) % 7;\n return zeroIndexed + 1;\n}\n\nexport interface IsoWeekDate {\n isoYear: number;\n week: number; // 1..53\n}\n\nexport function isoWeekYearAndWeek(year: number, month: number, day: number, dayOfWeek: number): IsoWeekDate {\n // Step 1: find the Thursday of the current ISO week. The ISO week-numbering\n // year is whichever calendar year that Thursday falls in. Computing it via\n // day-of-year offsets (rather than constructing a Temporal.PlainDate and\n // adding days) keeps this function pure-numeric.\n const doy = dayOfYear(year, month, day);\n const thursdayDoyRelative = doy + (4 - dayOfWeek); // may be <1 or >daysInYear\n\n let isoYear: number;\n let thursdayDoy: number;\n if (thursdayDoyRelative < 1) {\n isoYear = year - 1;\n thursdayDoy = thursdayDoyRelative + daysInYear(isoYear);\n } else if (thursdayDoyRelative > daysInYear(year)) {\n isoYear = year + 1;\n thursdayDoy = thursdayDoyRelative - daysInYear(year);\n } else {\n isoYear = year;\n thursdayDoy = thursdayDoyRelative;\n }\n\n // Step 2: locate the first Thursday of isoYear — its week is week 1. The\n // first Thursday's day-of-year depends on what weekday Jan 1 of isoYear is.\n const jan1Dow = dayOfWeekOfJan1(isoYear);\n const firstThursdayDoy = 1 + ((4 - jan1Dow + 7) % 7); // 1..7\n\n // Step 3: count full weeks between the two Thursdays.\n const week = 1 + Math.floor((thursdayDoy - firstThursdayDoy) / 7);\n return { isoYear, week };\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,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AAE,MAAS,WAAUC,EAAI,KAAOD,EAAE,MACzC,OAAOA,EAAE,OAAU,WAAUC,EAAI,MAAQD,EAAE,OAC3C,OAAOA,EAAE,KAAQ,WAAUC,EAAI,IAAMD,EAAE,KACvC,OAAOA,EAAE,MAAS,WAAUC,EAAI,KAAOD,EAAE,MACzC,OAAOA,EAAE,QAAW,WAAUC,EAAI,OAASD,EAAE,QAC7C,OAAOA,EAAE,QAAW,WAAUC,EAAI,OAASD,EAAE,QAC7C,OAAOA,EAAE,aAAgB,WAAUC,EAAI,YAAcD,EAAE,aACvD,OAAOA,EAAE,WAAc,WAAUC,EAAI,UAAYD,EAAE,WACnD,OAAOA,EAAE,YAAe,WAAUC,EAAI,WAAaD,EAAE,YACrDC,EAAI,OAAS,QAAaA,EAAI,QAAU,QAAaA,EAAI,MAAQ,OACnE,MAAM,IAAI,MACR,wHACF,EAEF,OAAOA,CACT","names":["calendarUtils_exports","__export","asDateFieldView","dayOfYearHelper","daysInMonth","daysInYear","endOf","getMonth","getQuarter","getWeekday","isLeapMonth","isLeapYear","monthsInYear","startOf","weekOfYear","weekYear","__toCommonJS","CUMULATIVE_DAYS_BY_MONTH","isGregorianLeapYear","year","daysInYear","dayOfYear","month","day","doy","REFERENCE_YEAR","dayOfWeekOfJan1","year","offset","REFERENCE_YEAR","y","daysInYear","isoWeekYearAndWeek","month","day","dayOfWeek","thursdayDoyRelative","dayOfYear","isoYear","thursdayDoy","firstThursdayDoy","week","requireFields","view","fields","f","daysInMonth","year","month","LENGTHS","isGregorianLeapYear","daysInYear","monthsInYear","_view","isLeapYear","isLeapMonth","dayOfYearHelper","dayOfYear","weekOfYear","isoWeekYearAndWeek","weekYear","validateStartMonth","startMonth","getQuarter","options","shifted","getMonth","getWeekday","touchesTime","unit","recomputeDayOfWeek","jsDow","startOf","value","result","asDateFieldView","endOf","v","out"]}
|
|
1
|
+
{"version":3,"sources":["../src/calendarUtils.ts","../src/isoWeek.ts"],"sourcesContent":["// Calendar utility helpers. These are pure functions\n// over the TemporalLike shape — no Temporal namespace needed, same\n// approach as isoWeek.ts and the field-reading helpers in format.ts.\n// Letting callers compute dayOfYear/weekOfYear/etc. without going\n// through format() means they can build their own derived values\n// without committing to a string format.\n//\n// Calendar-sensitivity: the helpers in this module assume the\n// iso8601 (Gregorian) calendar — that's what TemporalLike fields\n// carry for the overwhelming majority of callers. Non-Gregorian\n// calendars (hebrew, islamic, etc.) need their own helpers; this\n// module doesn't try to be calendar-polymorphic the way Temporal\n// itself is. Documented limitation, not a design choice — see\n// VERIFICATION.md for the rationale.\n\nimport { isGregorianLeapYear, dayOfYear, isoWeekYearAndWeek } from './isoWeek.js';\n\n// A subset of TemporalLike that has the date fields these helpers need,\n// plus optional time fields. PlainTime isn't a DateFieldView (no\n// year/month/day), but PlainDateTime / ZonedDateTime / PlainDate all\n// match. Time fields are optional so callers can pass a PlainDate\n// to startOf(value, 'month') without having to populate hour/minute/etc.\n// Exported so the comparison/arithmetic modules can use the same\n// narrowing.\nexport interface DateFieldView {\n year?: number;\n month?: number;\n day?: number;\n hour?: number;\n minute?: number;\n second?: number;\n millisecond?: number;\n dayOfWeek?: number;\n calendarId?: string;\n}\n\nfunction requireFields(view: DateFieldView, fields: Array<keyof DateFieldView>): void {\n for (const f of fields) {\n if (typeof view[f] !== 'number') {\n throw new Error(\n `temporal-fmt: calendar helper requires \"${String(f)}\", which this value doesn't have. ` +\n `Pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`\n );\n }\n }\n}\n\nexport function daysInMonth(view: DateFieldView): number {\n requireFields(view, ['year', 'month']);\n const { year, month } = view;\n // Standard Gregorian month lengths. February's length depends on\n // whether `year` is a leap year — the same isGregorianLeapYear check\n // isoWeek.ts uses for dayOfYear arithmetic.\n const LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n if (month === 2 && isGregorianLeapYear(year!)) return 29;\n return LENGTHS[(month! - 1)!]!;\n}\n\nexport function daysInYear(view: DateFieldView): 365 | 366 {\n requireFields(view, ['year']);\n return isGregorianLeapYear(view.year!) ? 366 : 365;\n}\n\nexport function monthsInYear(_view: DateFieldView): 12 {\n // Gregorian always has 12 months. Other calendars (Hebrew leap years\n // have 13) need calendar-aware logic this module doesn't carry — see\n // the file-level comment. The `_view` parameter is kept so the\n // signature mirrors the other helpers and a future calendar-aware\n // implementation can use it without changing call sites.\n return 12;\n}\n\nexport function isLeapYear(view: DateFieldView): boolean {\n requireFields(view, ['year']);\n return isGregorianLeapYear(view.year!);\n}\n\n// `isLeapMonth` would require knowing which month of a leap-year-aware\n// calendar is the leap month — Gregorian doesn't have one, so this\n// returns false unconditionally. Kept here so the public surface\n// matches the module's listing; non-Gregorian calendars need\n// a different implementation.\nexport function isLeapMonth(_view: DateFieldView): boolean {\n return false;\n}\n\nexport function dayOfYearHelper(view: DateFieldView): number {\n requireFields(view, ['year', 'month', 'day']);\n return dayOfYear(view.year!, view.month!, view.day!);\n}\n\n// ISO 8601 week and week-year. Delegates to isoWeek.ts's\n// isoWeekYearAndWeek, which does the full Thursday-of-week\n// computation to handle the year-boundary cases (Dec 29-31 belonging\n// to week 1 of next year, Jan 1-3 belonging to week 52/53 of the\n// previous year).\nexport function weekOfYear(view: DateFieldView): number {\n requireFields(view, ['year', 'month', 'day', 'dayOfWeek']);\n return isoWeekYearAndWeek(view.year!, view.month!, view.day!, view.dayOfWeek!).week;\n}\n\nexport function weekYear(view: DateFieldView): number {\n requireFields(view, ['year', 'month', 'day', 'dayOfWeek']);\n return isoWeekYearAndWeek(view.year!, view.month!, view.day!, view.dayOfWeek!).isoYear;\n}\n\n/**\n * Fiscal-quarter options. `startMonth` is the calendar month (1-12) the\n * fiscal year begins on — e.g. `7` for a fiscal year starting in July.\n * Omitted or `1` gives the calendar-quarter behavior getQuarter() has\n * always had (Jan-Mar = Q1, etc.), so existing callers passing nothing\n * see no change.\n */\nexport interface QuarterOptions {\n startMonth?: number;\n}\n\nfunction validateStartMonth(startMonth: number): void {\n if (!Number.isInteger(startMonth) || startMonth < 1 || startMonth > 12) {\n throw new Error(\n `temporal-fmt: getQuarter's startMonth must be an integer from 1 to 12 (got ${startMonth}).`\n );\n }\n}\n\nexport function getQuarter(view: DateFieldView, options: QuarterOptions = {}): number {\n requireFields(view, ['month']);\n const startMonth = options.startMonth ?? 1;\n validateStartMonth(startMonth);\n if (startMonth === 1) {\n // Mirrors the Q token: months 1-3 → Q1, 4-6 → Q2, 7-9 → Q3, 10-12 → Q4.\n return Math.ceil(view.month! / 3);\n }\n // Fiscal case: shift the month so startMonth becomes month 1 of the\n // fiscal year (mod 12, 1-indexed), then apply the same ceil(/3) rule.\n // E.g. startMonth=7 (fiscal year starts July): July→1, Aug→2, ...,\n // Dec→6, Jan→7, ..., June→12. Then Q1 = fiscal months 1-3 (Jul-Sep),\n // matching the common \"FY starts in July\" convention where Q1 is the\n // first quarter of the fiscal year, not a quarter numbered by which\n // calendar quarter it falls in.\n const shifted = ((view.month! - startMonth + 12) % 12) + 1;\n return Math.ceil(shifted / 3);\n}\n\n// `getMonth` / `getWeekday` look trivial (just read the field) but\n// they're kept as real functions for API surface consistency with the\n// rest of this module. They also normalize: getWeekday returns 1-7\n// (Mon-Sun, matching Temporal's spec) regardless of what numbering the\n// caller's underlying value uses.\nexport function getMonth(view: DateFieldView): number {\n requireFields(view, ['month']);\n return view.month!;\n}\n\nexport function getWeekday(view: DateFieldView): number {\n requireFields(view, ['dayOfWeek']);\n return view.dayOfWeek!;\n}\n\n// startOf / endOf return new field bags (not Temporal objects — this\n// module is polyfill-free) with the relevant fields zeroed/extended.\n// Callers can pass the result to a Temporal constructor if they want\n// a typed value.\nexport type StartOfUnit = 'day' | 'month' | 'year' | 'hour' | 'minute' | 'second';\n\n// Returns true if the given unit (when used with startOf/endOf) should\n// also touch the time fields. 'day', 'month', 'year' all imply a\n// resolution coarser than an hour, so startOf zeroes the time fields\n// and endOf maxes them. Sub-hour units (hour/minute/second) only touch\n// the fields finer than themselves.\nfunction touchesTime(unit: StartOfUnit): boolean {\n return unit === 'day' || unit === 'month' || unit === 'year';\n}\n\n// startOf/endOf reassign year/month/day, which invalidates any\n// dayOfWeek carried over from the input — a plain { ...view } spread\n// leaves the old value sitting there unchanged. Same failure mode\n// businessCalendar.ts's isBusinessDay() works around for add(); we\n// recompute here rather than trust the copied field.\nfunction recomputeDayOfWeek(view: DateFieldView): void {\n if (typeof view.dayOfWeek !== 'number') return;\n /* c8 ignore start @preserve -- unreachable: startOf()/endOf() both call\n * asDateFieldView() before this, which already throws if year/month/day\n * aren't all numbers — so by the time a value with a numeric dayOfWeek\n * reaches here, year/month/day are guaranteed present too. */\n if (typeof view.year !== 'number' || typeof view.month !== 'number' || typeof view.day !== 'number') return;\n /* c8 ignore stop @preserve */\n const jsDow = new Date(Date.UTC(view.year, view.month - 1, view.day)).getUTCDay(); // 0=Sun..6=Sat\n view.dayOfWeek = jsDow === 0 ? 7 : jsDow; // 1=Mon..7=Sun\n}\n\nexport function startOf(value: unknown, unit: StartOfUnit): DateFieldView {\n const view = asDateFieldView(value);\n const result: DateFieldView = { ...view };\n if (unit === 'year') {\n result.month = 1;\n result.day = 1;\n } else if (unit === 'month') {\n result.day = 1;\n }\n recomputeDayOfWeek(result);\n if (touchesTime(unit)) {\n result.hour = 0;\n result.minute = 0;\n result.second = 0;\n result.millisecond = 0;\n } else if (unit === 'hour') {\n result.minute = 0;\n result.second = 0;\n result.millisecond = 0;\n } else if (unit === 'minute') {\n result.second = 0;\n result.millisecond = 0;\n } else if (unit === 'second') {\n result.millisecond = 0;\n }\n return result;\n}\n\nexport function endOf(value: unknown, unit: StartOfUnit): DateFieldView {\n const view = asDateFieldView(value);\n const result: DateFieldView = { ...view };\n if (unit === 'year') {\n result.month = 12;\n result.day = daysInMonth({ year: result.year!, month: 12 });\n } else if (unit === 'month') {\n result.day = daysInMonth({ year: result.year!, month: result.month! });\n }\n recomputeDayOfWeek(result);\n if (touchesTime(unit)) {\n result.hour = 23;\n result.minute = 59;\n result.second = 59;\n result.millisecond = 999;\n } else if (unit === 'hour') {\n result.minute = 59;\n result.second = 59;\n result.millisecond = 999;\n } else if (unit === 'minute') {\n result.second = 59;\n result.millisecond = 999;\n } else if (unit === 'second') {\n result.millisecond = 999;\n }\n return result;\n}\n\n// Type-narrowing helpers used by the comparison/arithmetic modules.\n// Lets them accept any of the four date-carrying Temporal types without\n// importing Temporal itself.\nexport function asDateFieldView(value: unknown): DateFieldView {\n if (typeof value !== 'object' || value === null) {\n throw new Error(`temporal-fmt: expected a date-carrying Temporal value, got ${String(value)}.`);\n }\n // Temporal instances expose year/month/day/etc. as prototype getters,\n // not own enumerable properties — so `{ ...value }` would lose them.\n // Read them explicitly. Only the fields actually present on this\n // value type end up in the returned view.\n const v = value as Record<string, unknown>;\n const out: DateFieldView = {};\n if (typeof v.year === 'number') out.year = v.year;\n if (typeof v.month === 'number') out.month = v.month;\n if (typeof v.day === 'number') out.day = v.day;\n if (typeof v.hour === 'number') out.hour = v.hour;\n if (typeof v.minute === 'number') out.minute = v.minute;\n if (typeof v.second === 'number') out.second = v.second;\n if (typeof v.millisecond === 'number') out.millisecond = v.millisecond;\n if (typeof v.dayOfWeek === 'number') out.dayOfWeek = v.dayOfWeek;\n if (typeof v.calendarId === 'string') out.calendarId = v.calendarId;\n if (out.year === undefined || out.month === undefined || out.day === undefined) {\n throw new Error(\n `temporal-fmt: value is missing year/month/day fields — pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`\n );\n }\n return out;\n}\n\n// Re-export the TemporalType alias so callers can import everything\n// from one place.\nexport type { TemporalType } from './tokenMetadata.js';\n// Re-export TemporalLike for the same reason.\nexport type { TemporalLike } from './tokens.js';","// ISO week stuff. week runs Mon-Sun, and week 1 is whichever week has\n// the year's first Thursday in it (same as saying \"the week with Jan 4\").\n// took me a minute to wrap my head around this but the upshot is late-Dec\n// dates can land in week 1 of NEXT year, and early-Jan dates can land in\n// week 52/53 of the PREVIOUS year. that adjacent year is what RRRR prints,\n// not the plain calendar year.\n//\n// doing this with plain year/month/day + dayOfWeek math instead of asking\n// Temporal for it, since format() only has whatever fields got handed in\n// and dragging in a whole Temporal implementation just for week numbers\n// felt like overkill (also breaks for people not on setTemporal()).\n\nconst DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\nconst CUMULATIVE_DAYS_BY_MONTH = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];\n\nexport function isGregorianLeapYear(year: number): boolean {\n // divisible by 4, unless it's a century, then it also needs /400.\n // Temporal's iso8601 calendar never switches to Julian, so this rule\n // just applies all the way back, even for BCE years.\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n}\n\nfunction daysInYear(year: number): 365 | 366 {\n return isGregorianLeapYear(year) ? 366 : 365;\n}\n\nexport function dayOfYear(year: number, month: number, day: number): number {\n let doy = CUMULATIVE_DAYS_BY_MONTH[month - 1]! + day;\n if (month > 2 && isGregorianLeapYear(year)) doy += 1;\n return doy;\n}\n\n// Jan 1 2000 was a Saturday (ISO dow 6). picked this as an anchor point\n// since it's easier than reaching for Zeller's congruence every time,\n// and obviously this fact about Jan 1 2000 isn't going to change on us\nconst REFERENCE_YEAR = 2000;\nconst REFERENCE_JAN1_DAY_OF_WEEK = 6;\n\nfunction dayOfWeekOfJan1(year: number): number {\n // walk year by year from 2000 instead of doing this from scratch every\n // time — most callers pass a current-era year so this loop is short anyway\n let offset = 0;\n if (year >= REFERENCE_YEAR) {\n for (let y = REFERENCE_YEAR; y < year; y++) offset += daysInYear(y);\n } else {\n for (let y = year; y < REFERENCE_YEAR; y++) offset -= daysInYear(y);\n }\n // now turn \"days since Jan 1 2000\" into an ISO weekday. Jan 1 2000 was a 6\n // (Sat), so: zero-indexed = (6-1 + offset) mod 7, then bump back to 1-indexed\n const zeroIndexed = (((6 - 1 + offset) % 7) + 7) % 7;\n return zeroIndexed + 1;\n}\n\nexport interface IsoWeekDate {\n isoYear: number;\n week: number; // goes 1 to 53\n}\n\nexport function isoWeekYearAndWeek(year: number, month: number, day: number, dayOfWeek: number): IsoWeekDate {\n // step 1: figure out the Thursday of this week — whatever calendar year\n // that Thursday's in IS the ISO week-numbering year. doing this with\n // day-of-year offsets so we don't need an actual Temporal.PlainDate here\n const doy = dayOfYear(year, month, day);\n const thursdayDoyRelative = doy + (4 - dayOfWeek); // can go negative or past daysInYear, that's fine\n\n let isoYear: number;\n let thursdayDoy: number;\n if (thursdayDoyRelative < 1) {\n isoYear = year - 1;\n thursdayDoy = thursdayDoyRelative + daysInYear(isoYear);\n } else if (thursdayDoyRelative > daysInYear(year)) {\n isoYear = year + 1;\n thursdayDoy = thursdayDoyRelative - daysInYear(year);\n } else {\n isoYear = year;\n thursdayDoy = thursdayDoyRelative;\n }\n\n // step 2: find the first Thursday of isoYear, that one's week 1 by definition.\n // depends entirely on which weekday Jan 1 lands on\n const jan1Dow = dayOfWeekOfJan1(isoYear);\n const firstThursdayDoy = 1 + ((4 - jan1Dow + 7) % 7); // always lands somewhere 1-7\n\n // step 3: just count how many full weeks between the two Thursdays\n const week = 1 + Math.floor((thursdayDoy - firstThursdayDoy) / 7);\n return { isoYear, week };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaA,IAAM,2BAA2B,CAAC,GAAG,IAAI,IAAI,IAAI,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAEhF,SAAS,oBAAoB,MAAuB;AAIzD,SAAQ,OAAO,MAAM,KAAK,OAAO,QAAQ,KAAM,OAAO,QAAQ;AAChE;AAEA,SAAS,WAAW,MAAyB;AAC3C,SAAO,oBAAoB,IAAI,IAAI,MAAM;AAC3C;AAEO,SAAS,UAAU,MAAc,OAAe,KAAqB;AAC1E,MAAI,MAAM,yBAAyB,QAAQ,CAAC,IAAK;AACjD,MAAI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,EAAE,WAAW,SAAU,KAAI,SAAS,EAAE;AACjD,MAAI,OAAO,EAAE,WAAW,SAAU,KAAI,SAAS,EAAE;AACjD,MAAI,OAAO,EAAE,gBAAgB,SAAU,KAAI,cAAc,EAAE;AAC3D,MAAI,OAAO,EAAE,cAAc,SAAU,KAAI,YAAY,EAAE;AACvD,MAAI,OAAO,EAAE,eAAe,SAAU,KAAI,aAAa,EAAE;AACzD,MAAI,IAAI,SAAS,UAAa,IAAI,UAAU,UAAa,IAAI,QAAQ,QAAW;AAC9E,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":["daysInYear","daysInYear"]}
|
package/dist/calendarUtils.js
CHANGED
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import {
|
|
2
|
+
asDateFieldView,
|
|
3
|
+
dayOfYearHelper,
|
|
4
|
+
daysInMonth,
|
|
5
|
+
daysInYear,
|
|
6
|
+
endOf,
|
|
7
|
+
getMonth,
|
|
8
|
+
getQuarter,
|
|
9
|
+
getWeekday,
|
|
10
|
+
isLeapMonth,
|
|
11
|
+
isLeapYear,
|
|
12
|
+
monthsInYear,
|
|
13
|
+
startOf,
|
|
14
|
+
weekOfYear,
|
|
15
|
+
weekYear
|
|
16
|
+
} from "./chunk-HXY2GUUM.js";
|
|
17
|
+
import "./chunk-MKPDLQKD.js";
|
|
18
|
+
export {
|
|
19
|
+
asDateFieldView,
|
|
20
|
+
dayOfYearHelper,
|
|
21
|
+
daysInMonth,
|
|
22
|
+
daysInYear,
|
|
23
|
+
endOf,
|
|
24
|
+
getMonth,
|
|
25
|
+
getQuarter,
|
|
26
|
+
getWeekday,
|
|
27
|
+
isLeapMonth,
|
|
28
|
+
isLeapYear,
|
|
29
|
+
monthsInYear,
|
|
30
|
+
startOf,
|
|
31
|
+
weekOfYear,
|
|
32
|
+
weekYear
|
|
33
|
+
};
|
|
2
34
|
//# sourceMappingURL=calendarUtils.js.map
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyNumbering,
|
|
3
|
+
tokenize
|
|
4
|
+
} from "./chunk-M3GDTHMT.js";
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_LOCALE,
|
|
7
|
+
TOKENS
|
|
8
|
+
} from "./chunk-L24NPTAJ.js";
|
|
9
|
+
import {
|
|
10
|
+
MAX_FORMAT_LENGTH
|
|
11
|
+
} from "./chunk-YEUASGDK.js";
|
|
12
|
+
import {
|
|
13
|
+
FormatSyntaxError,
|
|
14
|
+
UnknownTokenError
|
|
15
|
+
} from "./chunk-EGUUO6LE.js";
|
|
16
|
+
|
|
17
|
+
// src/format.ts
|
|
18
|
+
var HANDLER_BY_TOKEN = new Map(TOKENS.map(([tok, fn, field]) => [tok, { fn, field }]));
|
|
19
|
+
var tokenizeCache = /* @__PURE__ */ new Map();
|
|
20
|
+
var MAX_TOKENIZE_CACHE_SIZE = 500;
|
|
21
|
+
function getPieces(formatStr) {
|
|
22
|
+
let pieces = tokenizeCache.get(formatStr);
|
|
23
|
+
if (pieces) return pieces;
|
|
24
|
+
if (tokenizeCache.size >= MAX_TOKENIZE_CACHE_SIZE) {
|
|
25
|
+
const oldestKey = tokenizeCache.keys().next().value;
|
|
26
|
+
if (oldestKey !== void 0) tokenizeCache.delete(oldestKey);
|
|
27
|
+
}
|
|
28
|
+
pieces = tokenize(formatStr);
|
|
29
|
+
tokenizeCache.set(formatStr, pieces);
|
|
30
|
+
return pieces;
|
|
31
|
+
}
|
|
32
|
+
function format(temporal, formatStr, options = {}) {
|
|
33
|
+
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
34
|
+
throw new FormatSyntaxError({
|
|
35
|
+
format: formatStr,
|
|
36
|
+
message: `temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
40
|
+
const pieces = getPieces(formatStr);
|
|
41
|
+
let result = "";
|
|
42
|
+
for (const piece of pieces) {
|
|
43
|
+
if (piece.kind === "literal") {
|
|
44
|
+
result += piece.value;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const handler = HANDLER_BY_TOKEN.get(piece.value);
|
|
48
|
+
/* c8 ignore start @preserve -- unreachable: tokenize() only ever emits
|
|
49
|
+
tokens present in TOKENS, and HANDLER_BY_TOKEN is built from that
|
|
50
|
+
same list, so every token piece.value can hold already has an entry
|
|
51
|
+
here. Same defensive-guard category as the twin checks in
|
|
52
|
+
analyze.ts/formatDuration.ts. */
|
|
53
|
+
if (!handler) {
|
|
54
|
+
throw new UnknownTokenError({ token: piece.value, format: formatStr, message: `temporal-fmt: unknown token "${piece.value}"` });
|
|
55
|
+
}
|
|
56
|
+
/* c8 ignore stop @preserve */
|
|
57
|
+
if (temporal[handler.field] === void 0) {
|
|
58
|
+
throw new FormatSyntaxError({
|
|
59
|
+
format: formatStr,
|
|
60
|
+
token: piece.value,
|
|
61
|
+
message: `temporal-fmt: token "${piece.value}" requires "${handler.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
result += handler.fn(temporal, locale);
|
|
65
|
+
}
|
|
66
|
+
return applyNumbering(result, options);
|
|
67
|
+
}
|
|
68
|
+
function formatToParts(temporal, formatStr, options = {}) {
|
|
69
|
+
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
70
|
+
throw new FormatSyntaxError({
|
|
71
|
+
format: formatStr,
|
|
72
|
+
message: `temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
76
|
+
const pieces = getPieces(formatStr);
|
|
77
|
+
const result = [];
|
|
78
|
+
for (const piece of pieces) {
|
|
79
|
+
if (piece.kind === "literal") {
|
|
80
|
+
const last = result[result.length - 1];
|
|
81
|
+
/* c8 ignore start @preserve -- unreachable through tokenize()'s own
|
|
82
|
+
output: appendLiteral() in tokenize.ts already merges every
|
|
83
|
+
adjacent literal character before pieces ever reaches here, so
|
|
84
|
+
two 'literal' pieces never sit back-to-back in the array this
|
|
85
|
+
loop walks. Kept as defense-in-depth in case that invariant ever
|
|
86
|
+
changes upstream. */
|
|
87
|
+
if (last && last.type === "literal") {
|
|
88
|
+
last.value += piece.value;
|
|
89
|
+
} else {
|
|
90
|
+
/* c8 ignore stop @preserve */
|
|
91
|
+
result.push({ type: "literal", value: piece.value });
|
|
92
|
+
}
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const handler = HANDLER_BY_TOKEN.get(piece.value);
|
|
96
|
+
/* c8 ignore start @preserve -- unreachable, see the note in format() above */
|
|
97
|
+
if (!handler) {
|
|
98
|
+
throw new UnknownTokenError({ token: piece.value, format: formatStr, message: `temporal-fmt: unknown token "${piece.value}"` });
|
|
99
|
+
}
|
|
100
|
+
/* c8 ignore stop @preserve */
|
|
101
|
+
if (temporal[handler.field] === void 0) {
|
|
102
|
+
throw new FormatSyntaxError({
|
|
103
|
+
format: formatStr,
|
|
104
|
+
token: piece.value,
|
|
105
|
+
message: `temporal-fmt: token "${piece.value}" requires "${handler.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
result.push({ type: "token", value: applyNumbering(handler.fn(temporal, locale), options), token: piece.value });
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
function compileFormat(formatStr) {
|
|
113
|
+
if (formatStr.length > MAX_FORMAT_LENGTH) {
|
|
114
|
+
throw new FormatSyntaxError({
|
|
115
|
+
format: formatStr,
|
|
116
|
+
message: `temporal-fmt: format string exceeds maximum length of ${MAX_FORMAT_LENGTH} characters (got ${formatStr.length}).`
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const pieces = getPieces(formatStr);
|
|
120
|
+
return {
|
|
121
|
+
formatStr,
|
|
122
|
+
pieces,
|
|
123
|
+
format(temporal, options = {}) {
|
|
124
|
+
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
125
|
+
let result = "";
|
|
126
|
+
for (const piece of pieces) {
|
|
127
|
+
if (piece.kind === "literal") {
|
|
128
|
+
result += piece.value;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const handler = HANDLER_BY_TOKEN.get(piece.value);
|
|
132
|
+
if (!handler) throw new UnknownTokenError({ token: piece.value, format: formatStr, message: `temporal-fmt: unknown token "${piece.value}"` });
|
|
133
|
+
if (temporal[handler.field] === void 0) {
|
|
134
|
+
throw new FormatSyntaxError({
|
|
135
|
+
format: formatStr,
|
|
136
|
+
token: piece.value,
|
|
137
|
+
message: `temporal-fmt: token "${piece.value}" requires "${handler.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
result += handler.fn(temporal, locale);
|
|
141
|
+
}
|
|
142
|
+
return applyNumbering(result, options);
|
|
143
|
+
},
|
|
144
|
+
formatToParts(temporal, options = {}) {
|
|
145
|
+
const locale = options.locale ?? DEFAULT_LOCALE;
|
|
146
|
+
const out = [];
|
|
147
|
+
for (const piece of pieces) {
|
|
148
|
+
if (piece.kind === "literal") {
|
|
149
|
+
const last = out[out.length - 1];
|
|
150
|
+
if (last && last.type === "literal") last.value += piece.value;
|
|
151
|
+
else out.push({ type: "literal", value: piece.value });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const handler = HANDLER_BY_TOKEN.get(piece.value);
|
|
155
|
+
if (!handler) throw new UnknownTokenError({ token: piece.value, format: formatStr, message: `temporal-fmt: unknown token "${piece.value}"` });
|
|
156
|
+
if (temporal[handler.field] === void 0) {
|
|
157
|
+
throw new FormatSyntaxError({
|
|
158
|
+
format: formatStr,
|
|
159
|
+
token: piece.value,
|
|
160
|
+
message: `temporal-fmt: token "${piece.value}" requires "${handler.field}", which this Temporal object doesn't have. (e.g. PlainDate has no time fields, PlainTime has no date fields)`
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
out.push({ type: "token", value: applyNumbering(handler.fn(temporal, locale), options), token: piece.value });
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function _getPieces(formatStr) {
|
|
170
|
+
return getPieces(formatStr);
|
|
171
|
+
}
|
|
172
|
+
function _handlerFor(token) {
|
|
173
|
+
return HANDLER_BY_TOKEN.get(token);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export {
|
|
177
|
+
format,
|
|
178
|
+
formatToParts,
|
|
179
|
+
compileFormat,
|
|
180
|
+
_getPieces,
|
|
181
|
+
_handlerFor
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=chunk-4N3WCGEY.js.map
|