temporal-fmt 0.9.2 → 0.9.4

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 (103) hide show
  1. package/README.md +480 -9
  2. package/dist/calendarUtils.cjs +259 -4
  3. package/dist/calendarUtils.cjs.map +1 -1
  4. package/dist/calendarUtils.js +33 -1
  5. package/dist/chunk-4N3WCGEY.js +183 -0
  6. package/dist/{chunk-4JWGUR4O.js.map → chunk-4N3WCGEY.js.map} +1 -1
  7. package/dist/chunk-5UTV5VP6.js +984 -0
  8. package/dist/chunk-5UTV5VP6.js.map +1 -0
  9. package/dist/chunk-ACKKWH5Z.js +578 -0
  10. package/dist/{chunk-2JHEV7ZF.js.map → chunk-ACKKWH5Z.js.map} +1 -1
  11. package/dist/chunk-EGUUO6LE.js +439 -0
  12. package/dist/chunk-EGUUO6LE.js.map +1 -0
  13. package/dist/chunk-FBPHNRVW.js +2939 -0
  14. package/dist/chunk-FBPHNRVW.js.map +1 -0
  15. package/dist/chunk-GPB4JHGI.js +65 -0
  16. package/dist/chunk-GPB4JHGI.js.map +1 -0
  17. package/dist/chunk-H7YQX25T.js +170 -0
  18. package/dist/{chunk-J2AQNXF2.js.map → chunk-H7YQX25T.js.map} +1 -1
  19. package/dist/chunk-HXY2GUUM.js +182 -0
  20. package/dist/{chunk-EHLRZULM.js.map → chunk-HXY2GUUM.js.map} +1 -1
  21. package/dist/chunk-L24NPTAJ.js +328 -0
  22. package/dist/chunk-L24NPTAJ.js.map +1 -0
  23. package/dist/chunk-M3GDTHMT.js +169 -0
  24. package/dist/chunk-M3GDTHMT.js.map +1 -0
  25. package/dist/chunk-MKPDLQKD.js +51 -0
  26. package/dist/chunk-MKPDLQKD.js.map +1 -0
  27. package/dist/chunk-TSLPIURC.js +242 -0
  28. package/dist/{chunk-VQXUMFB2.js.map → chunk-TSLPIURC.js.map} +1 -1
  29. package/dist/chunk-UOPAV3WX.js +75 -0
  30. package/dist/chunk-UOPAV3WX.js.map +1 -0
  31. package/dist/chunk-VNIUIQA4.js +398 -0
  32. package/dist/chunk-VNIUIQA4.js.map +1 -0
  33. package/dist/chunk-YEUASGDK.js +9 -0
  34. package/dist/chunk-YEUASGDK.js.map +1 -0
  35. package/dist/chunk-ZQZF5EXW.js +29 -0
  36. package/dist/chunk-ZQZF5EXW.js.map +1 -0
  37. package/dist/config.d.cts +4 -2
  38. package/dist/config.d.ts +4 -2
  39. package/dist/duration.cjs +638 -26
  40. package/dist/duration.cjs.map +1 -1
  41. package/dist/duration.js +28 -1
  42. package/dist/format.cjs +833 -35
  43. package/dist/format.cjs.map +1 -1
  44. package/dist/format.js +20 -1
  45. package/dist/index.cjs +7698 -163
  46. package/dist/index.cjs.map +1 -1
  47. package/dist/index.d.cts +108 -24
  48. package/dist/index.d.ts +108 -24
  49. package/dist/index.js +1536 -58
  50. package/dist/index.js.map +1 -1
  51. package/dist/interval.cjs +5480 -35
  52. package/dist/interval.cjs.map +1 -1
  53. package/dist/interval.js +46 -1
  54. package/dist/localeRegistry.cjs +375 -32
  55. package/dist/localeRegistry.cjs.map +1 -1
  56. package/dist/localeRegistry.js +11 -1
  57. package/dist/modApi.d.cts +131 -0
  58. package/dist/modApi.d.ts +131 -0
  59. package/dist/parse.cjs +1797 -70
  60. package/dist/parse.cjs.map +1 -1
  61. package/dist/parse.js +20 -1
  62. package/dist/pattern.d.cts +1 -0
  63. package/dist/pattern.d.ts +1 -0
  64. package/dist/recurrence.cjs +452 -20
  65. package/dist/recurrence.cjs.map +1 -1
  66. package/dist/recurrence.js +19 -1
  67. package/dist/relativeTime.cjs +268 -21
  68. package/dist/relativeTime.cjs.map +1 -1
  69. package/dist/relativeTime.js +14 -1
  70. package/dist/runtime.d.cts +201 -0
  71. package/dist/runtime.d.ts +201 -0
  72. package/dist/timezone.cjs +387 -20
  73. package/dist/timezone.cjs.map +1 -1
  74. package/dist/timezone.js +26 -1
  75. package/package.json +4 -6
  76. package/scripts/cli.mjs +27 -5
  77. package/dist/chunk-2JHEV7ZF.js +0 -7
  78. package/dist/chunk-3MZLTVP3.js +0 -2
  79. package/dist/chunk-3MZLTVP3.js.map +0 -1
  80. package/dist/chunk-4JWGUR4O.js +0 -11
  81. package/dist/chunk-5U5WJ465.js +0 -36
  82. package/dist/chunk-5U5WJ465.js.map +0 -1
  83. package/dist/chunk-C5YESWFT.js +0 -2
  84. package/dist/chunk-C5YESWFT.js.map +0 -1
  85. package/dist/chunk-C6ZZ62ET.js +0 -2
  86. package/dist/chunk-C6ZZ62ET.js.map +0 -1
  87. package/dist/chunk-EHLRZULM.js +0 -5
  88. package/dist/chunk-F4RGUDA3.js +0 -2
  89. package/dist/chunk-F4RGUDA3.js.map +0 -1
  90. package/dist/chunk-J2AQNXF2.js +0 -2
  91. package/dist/chunk-NBXF7V5B.js +0 -2
  92. package/dist/chunk-NBXF7V5B.js.map +0 -1
  93. package/dist/chunk-R52YOKI3.js +0 -7
  94. package/dist/chunk-R52YOKI3.js.map +0 -1
  95. package/dist/chunk-UJR6DHXY.js +0 -2
  96. package/dist/chunk-UJR6DHXY.js.map +0 -1
  97. package/dist/chunk-VQXUMFB2.js +0 -21
  98. package/dist/chunk-XH46JNPK.js +0 -2
  99. package/dist/chunk-XH46JNPK.js.map +0 -1
  100. package/dist/chunk-YB6YAG7E.js +0 -35
  101. package/dist/chunk-YB6YAG7E.js.map +0 -1
  102. package/dist/chunk-ZGMTY52O.js +0 -2
  103. package/dist/chunk-ZGMTY52O.js.map +0 -1
package/dist/timezone.cjs CHANGED
@@ -1,21 +1,388 @@
1
- "use strict";var D=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var Y=(e,n)=>{for(var t in n)D(e,t,{get:n[t],enumerable:!0})},U=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of V(n))!Z.call(e,o)&&o!==t&&D(e,o,{get:()=>n[o],enumerable:!(r=N(n,o))||r.enumerable});return e};var W=e=>U(D({},"__esModule",{value:!0}),e);var z={};Y(z,{getNextTransition:()=>J,getOffset:()=>Q,getOffsetNanoseconds:()=>q,getPreviousTransition:()=>B,getTimeZone:()=>L,getTransitions:()=>K,isDST:()=>G,possibleInstantsFor:()=>X,resolveZoned:()=>H});module.exports=W(z);var A;function C(){return A??globalThis.Temporal}function f(){let e=C();if(!e)throw new Error("temporal-fmt: parse() needs a Temporal implementation to construct its result. Call setTemporal(Temporal) once at startup, or assign one to globalThis.Temporal (native on Node 26+, or a polyfill like temporal-polyfill).");return e}function O(e){return e%4===0&&e%100!==0||e%400===0}function $(e,n){for(let t of n)if(typeof e[t]!="number")throw new Error(`temporal-fmt: calendar helper requires "${String(t)}", which this value doesn't have. Pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`)}function T(e){$(e,["year","month"]);let{year:n,month:t}=e,r=[31,28,31,30,31,30,31,31,30,31,30,31];return t===2&&O(n)?29:r[t-1]}function I(e){if(typeof e!="object"||e===null)throw new Error(`temporal-fmt: expected a date-carrying Temporal value, got ${String(e)}.`);let n=e,t={};if(typeof n.year=="number"&&(t.year=n.year),typeof n.month=="number"&&(t.month=n.month),typeof n.day=="number"&&(t.day=n.day),typeof n.hour=="number"&&(t.hour=n.hour),typeof n.minute=="number"&&(t.minute=n.minute),typeof n.second=="number"&&(t.second=n.second),typeof n.millisecond=="number"&&(t.millisecond=n.millisecond),typeof n.dayOfWeek=="number"&&(t.dayOfWeek=n.dayOfWeek),typeof n.calendarId=="string"&&(t.calendarId=n.calendarId),t.year===void 0||t.month===void 0||t.day===void 0)throw new Error("temporal-fmt: value is missing year/month/day fields \u2014 pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.");return t}function j(e){return I(e)}function g(e){if(typeof e.dayOfWeek!="number")return;/* c8 ignore start @preserve -- unreachable: every call site (add()'s
2
- 'years'/'months' cases, shiftDays()) passes a `result` whose
3
- year/month/day were just explicitly set, and the value originally
4
- came from asDateTime()/asDateFieldView(), which throws unless
5
- year/month/day are all present as numbers. So by the time this guard
6
- runs, all three are guaranteed valid. Kept in case a future caller
7
- constructs a DateTimeFieldView bypassing that validation. */if(typeof e.year!="number"||typeof e.month!="number"||typeof e.day!="number")return;/* c8 ignore stop @preserve */let n=new Date(Date.UTC(e.year,e.month-1,e.day)).getUTCDay();e.dayOfWeek=n===0?7:n}function b(e,n,t){let o={...j(e)};switch(t){case"years":{/* c8 ignore start @preserve -- the `?? 0` fallback is unreachable:
8
- asDateTime()/asDateFieldView() (called at the top of add()) throws
9
- unless year is present as a number, so result.year is never
10
- undefined here. Kept as a guard against a future change that
11
- relaxes that validation. */o.year=(o.year??0)+n;/* c8 ignore stop @preserve */let s=T({year:o.year,month:o.month});o.day>s&&(o.day=s),g(o);break}case"months":{/* c8 ignore start @preserve -- both `??` fallbacks are unreachable
12
- for the same reason as the 'years' case above: asDateFieldView()
13
- guarantees year and month are present numbers before add() ever
14
- reaches here. */let s=(o.year??0)*12+(o.month??1)-1+n;/* c8 ignore stop @preserve */o.year=Math.floor(s/12),o.month=s%12+1,o.month<1&&(o.month+=12,o.year-=1);/* c8 ignore start @preserve -- unreachable: (total % 12) + 1 can never
15
- exceed 12 for any integer total in JS (its range is [-10, 12] since
16
- JS's % can return a negative remainder but never one with
17
- magnitude >= 12, so adding 1 tops out at 12). Only the < 1 branch
18
- above is reachable; this was written symmetrically with it but the
19
- overflow direction it guards against can't occur. Kept rather than
20
- removed since it costs nothing and documents the intent. */o.month>12&&(o.month-=12,o.year+=1);/* c8 ignore stop @preserve */let a=T({year:o.year,month:o.month});o.day>a&&(o.day=a),g(o);break}case"weeks":o=M(o,n*7);break;case"days":o=M(o,n);break;case"hours":o=k(o,n*36e5);break;case"minutes":o=k(o,n*6e4);break;case"seconds":o=k(o,n*1e3);break;case"milliseconds":o=k(o,n);break}return o}function M(e,n){let t=e.year,r=e.month,o=e.day,s=r<=2?t-1:t,a=Math.floor((s>=0?s:s-399)/400),i=s-a*400,m=r>2?r-3:r+9,c=Math.floor((153*m+2)/5)+o-1,l=i*365+Math.floor(i/4)-Math.floor(i/100)+c,d=a*146097+l-719468+n+719468,y=Math.floor((d>=0?d:d-146096)/146097),p=d-y*146097,h=Math.floor((p-Math.floor(p/1460)+Math.floor(p/36524)-Math.floor(p/146096))/365),_=h+y*400,x=p-(365*h+Math.floor(h/4)-Math.floor(h/100)),w=Math.floor((5*x+2)/153),P=x-Math.floor((153*w+2)/5)+1,E=w<10?w+3:w-9,R=E<=2?_+1:_,F={...e,year:R,month:E,day:P};return g(F),F}function k(e,n){let a=(e.hour??0)*36e5+(e.minute??0)*6e4+(e.second??0)*1e3+(e.millisecond??0)+n,i=Math.floor(a/864e5),m=a%864e5;m<0&&(m+=864e5);let c=Math.floor(m/36e5),l=Math.floor(m%36e5/6e4),u=Math.floor(m%6e4/1e3),d=m%1e3,y={...e,hour:c,minute:l,second:u,millisecond:d};return i!==0?M(y,i):y}function H(e,n,t={}){let r=f(),o=t.disambiguation??"compatible",a={overflow:t.overflow??"constrain",disambiguation:o,offset:t.offset??"prefer"};try{return r.ZonedDateTime.from({year:e.year,month:e.month,day:e.day,hour:e.hour??0,minute:e.minute??0,second:e.second??0,millisecond:e.millisecond??0,microsecond:e.microsecond??0,nanosecond:e.nanosecond??0,timeZone:n},a)}catch(i){let m=i.message;throw/no such (wall-clock )?time/i.test(m)&&o==="reject"?new Error(`temporal-fmt: "${n}" has no such wall-clock time on ${e.year}-${e.month}-${e.day}T${e.hour??0}:${e.minute??0} \u2014 it falls in a DST gap. Pass { disambiguation: 'compatible' | 'earlier' | 'later' } to pick an instant.`):i}}function L(e){let n=e;if(typeof n?.timeZoneId!="string")throw new Error(`temporal-fmt: getTimeZone() expected a ZonedDateTime, got ${typeof e}.`);return n.timeZoneId}function Q(e){let n=e;if(typeof n?.offset!="string")throw new Error(`temporal-fmt: getOffset() expected a ZonedDateTime, got ${typeof e}.`);return n.offset}function q(e){let n=e;if(typeof n?.offsetNanoseconds=="number")return n.offsetNanoseconds;if(typeof n?.offset=="string"){let t=n.offset.match(/^([+-])(\d{2}):(\d{2})$/);if(!t)throw new Error(`temporal-fmt: getOffsetNanoseconds() couldn't parse offset "${n.offset}".`);return(t[1]==="-"?-1:1)*(Number(t[2])*3600+Number(t[3])*60)*1e9}throw new Error(`temporal-fmt: getOffsetNanoseconds() expected a ZonedDateTime, got ${typeof e}.`)}function G(e){let n=e;if(typeof n?.timeZoneId!="string"||typeof n?.offset!="string"||typeof n?.year!="number")throw new Error(`temporal-fmt: isDST() expected a ZonedDateTime, got ${typeof e}.`);let t=f();try{return t.ZonedDateTime.from({year:n.year,month:1,day:1,hour:12,timeZone:n.timeZoneId},{disambiguation:"compatible"}).offset!==n.offset}catch{return!1}}function J(e){return S(e,1)}function B(e){return S(e,-1)}function S(e,n){let t=e;if(typeof t?.timeZoneId!="string")throw new Error(`temporal-fmt: ${n>0?"getNextTransition":"getPreviousTransition"}() expected a ZonedDateTime, got ${typeof e}.`);let r=f(),o=t.timeZoneId,s=b(e,n,"days"),a=t.offset;for(let i=0;i<365*2;i++){let m=s,c=r.ZonedDateTime.from({...m,timeZone:o},{disambiguation:"compatible"});if(c.offset!==a)return c;s=b(s,n,"days")}}function K(e,n){let t=[],r=e;if(typeof r?.timeZoneId!="string")throw new Error(`temporal-fmt: getTransitions() expected a ZonedDateTime for start, got ${typeof e}.`);let o=n,s=f(),a=r.timeZoneId,i=b(e,1,"days"),m=r.offset;for(let c=0;c<365*5;c++){let l=i,u=s.ZonedDateTime.from({...l,timeZone:a},{disambiguation:"compatible"});if(u.offset!==m){if(u.year>o.year||u.year===o.year&&(u.month>o.month||u.month===o.month&&u.day>o.day))break;t.push(u),m=u.offset}i=b(i,1,"days")}return t}function X(e,n){let t=f(),r=t.ZonedDateTime.from({...e,timeZone:n},{disambiguation:"earlier",offset:"ignore"}),o=t.ZonedDateTime.from({...e,timeZone:n},{disambiguation:"later",offset:"ignore"}),s=a=>a.year===e.year&&a.month===e.month&&a.day===e.day&&a.hour===e.hour&&a.minute===e.minute&&a.second===e.second&&a.millisecond===e.millisecond;return!s(r)||!s(o)?[]:r.toInstant().epochNanoseconds===o.toInstant().epochNanoseconds?[r]:[r,o]}0&&(module.exports={getNextTransition,getOffset,getOffsetNanoseconds,getPreviousTransition,getTimeZone,getTransitions,isDST,possibleInstantsFor,resolveZoned});
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/timezone.ts
21
+ var timezone_exports = {};
22
+ __export(timezone_exports, {
23
+ getNextTransition: () => getNextTransition,
24
+ getOffset: () => getOffset,
25
+ getOffsetNanoseconds: () => getOffsetNanoseconds,
26
+ getPreviousTransition: () => getPreviousTransition,
27
+ getTimeZone: () => getTimeZone,
28
+ getTransitions: () => getTransitions,
29
+ isDST: () => isDST,
30
+ possibleInstantsFor: () => possibleInstantsFor,
31
+ resolveZoned: () => resolveZoned
32
+ });
33
+ module.exports = __toCommonJS(timezone_exports);
34
+
35
+ // src/temporalProvider.ts
36
+ var injectedTemporal;
37
+ function resolveTemporal() {
38
+ return injectedTemporal ?? globalThis.Temporal;
39
+ }
40
+ function getTemporal() {
41
+ const temporal = resolveTemporal();
42
+ if (!temporal) {
43
+ throw new Error(
44
+ "temporal-fmt: parse() needs a Temporal implementation to construct its result. Call setTemporal(Temporal) once at startup, or assign one to globalThis.Temporal (native on Node 26+, or a polyfill like temporal-polyfill)."
45
+ );
46
+ }
47
+ return temporal;
48
+ }
49
+
50
+ // src/isoWeek.ts
51
+ function isGregorianLeapYear(year) {
52
+ return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
53
+ }
54
+
55
+ // src/calendarUtils.ts
56
+ function requireFields(view, fields) {
57
+ for (const f of fields) {
58
+ if (typeof view[f] !== "number") {
59
+ throw new Error(
60
+ `temporal-fmt: calendar helper requires "${String(f)}", which this value doesn't have. Pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`
61
+ );
62
+ }
63
+ }
64
+ }
65
+ function daysInMonth(view) {
66
+ requireFields(view, ["year", "month"]);
67
+ const { year, month } = view;
68
+ const LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
69
+ if (month === 2 && isGregorianLeapYear(year)) return 29;
70
+ return LENGTHS[month - 1];
71
+ }
72
+ function asDateFieldView(value) {
73
+ if (typeof value !== "object" || value === null) {
74
+ throw new Error(`temporal-fmt: expected a date-carrying Temporal value, got ${String(value)}.`);
75
+ }
76
+ const v = value;
77
+ const out = {};
78
+ if (typeof v.year === "number") out.year = v.year;
79
+ if (typeof v.month === "number") out.month = v.month;
80
+ if (typeof v.day === "number") out.day = v.day;
81
+ if (typeof v.hour === "number") out.hour = v.hour;
82
+ if (typeof v.minute === "number") out.minute = v.minute;
83
+ if (typeof v.second === "number") out.second = v.second;
84
+ if (typeof v.millisecond === "number") out.millisecond = v.millisecond;
85
+ if (typeof v.dayOfWeek === "number") out.dayOfWeek = v.dayOfWeek;
86
+ if (typeof v.calendarId === "string") out.calendarId = v.calendarId;
87
+ if (out.year === void 0 || out.month === void 0 || out.day === void 0) {
88
+ throw new Error(
89
+ `temporal-fmt: value is missing year/month/day fields \u2014 pass a Temporal.PlainDate / PlainDateTime / ZonedDateTime.`
90
+ );
91
+ }
92
+ return out;
93
+ }
94
+
95
+ // src/arithmetic.ts
96
+ function asDateTime(value) {
97
+ return asDateFieldView(value);
98
+ }
99
+ function recomputeDayOfWeek(view) {
100
+ if (typeof view.dayOfWeek !== "number") return;
101
+ /* c8 ignore start @preserve -- unreachable: every call site (add()'s
102
+ 'years'/'months' cases, shiftDays()) passes a `result` whose
103
+ year/month/day were just explicitly set, and the value originally
104
+ came from asDateTime()/asDateFieldView(), which throws unless
105
+ year/month/day are all present as numbers. So by the time this guard
106
+ runs, all three are guaranteed valid. Kept in case a future caller
107
+ constructs a DateTimeFieldView bypassing that validation. */
108
+ if (typeof view.year !== "number" || typeof view.month !== "number" || typeof view.day !== "number") return;
109
+ /* c8 ignore stop @preserve */
110
+ const jsDow = new Date(Date.UTC(view.year, view.month - 1, view.day)).getUTCDay();
111
+ view.dayOfWeek = jsDow === 0 ? 7 : jsDow;
112
+ }
113
+ function add(value, amount, unit) {
114
+ const v = asDateTime(value);
115
+ let result = { ...v };
116
+ switch (unit) {
117
+ case "years": {
118
+ /* c8 ignore start @preserve -- the `?? 0` fallback is unreachable:
119
+ asDateTime()/asDateFieldView() (called at the top of add()) throws
120
+ unless year is present as a number, so result.year is never
121
+ undefined here. Kept as a guard against a future change that
122
+ relaxes that validation. */
123
+ result.year = (result.year ?? 0) + amount;
124
+ /* c8 ignore stop @preserve */
125
+ const maxDay = daysInMonth({ year: result.year, month: result.month });
126
+ if (result.day > maxDay) result.day = maxDay;
127
+ recomputeDayOfWeek(result);
128
+ break;
129
+ }
130
+ case "months": {
131
+ /* c8 ignore start @preserve -- both `??` fallbacks are unreachable
132
+ for the same reason as the 'years' case above: asDateFieldView()
133
+ guarantees year and month are present numbers before add() ever
134
+ reaches here. */
135
+ const total = (result.year ?? 0) * 12 + (result.month ?? 1) - 1 + amount;
136
+ /* c8 ignore stop @preserve */
137
+ result.year = Math.floor(total / 12);
138
+ result.month = total % 12 + 1;
139
+ if (result.month < 1) {
140
+ result.month += 12;
141
+ result.year -= 1;
142
+ }
143
+ /* c8 ignore start @preserve -- unreachable: (total % 12) + 1 can never
144
+ exceed 12 for any integer total in JS (its range is [-10, 12] since
145
+ JS's % can return a negative remainder but never one with
146
+ magnitude >= 12, so adding 1 tops out at 12). Only the < 1 branch
147
+ above is reachable; this was written symmetrically with it but the
148
+ overflow direction it guards against can't occur. Kept rather than
149
+ removed since it costs nothing and documents the intent. */
150
+ if (result.month > 12) {
151
+ result.month -= 12;
152
+ result.year += 1;
153
+ }
154
+ /* c8 ignore stop @preserve */
155
+ const maxDay = daysInMonth({ year: result.year, month: result.month });
156
+ if (result.day > maxDay) result.day = maxDay;
157
+ recomputeDayOfWeek(result);
158
+ break;
159
+ }
160
+ case "weeks":
161
+ result = shiftDays(result, amount * 7);
162
+ break;
163
+ case "days":
164
+ result = shiftDays(result, amount);
165
+ break;
166
+ case "hours":
167
+ result = shiftTime(result, amount * 36e5);
168
+ break;
169
+ case "minutes":
170
+ result = shiftTime(result, amount * 6e4);
171
+ break;
172
+ case "seconds":
173
+ result = shiftTime(result, amount * 1e3);
174
+ break;
175
+ case "milliseconds":
176
+ result = shiftTime(result, amount);
177
+ break;
178
+ }
179
+ return result;
180
+ }
181
+ function shiftDays(v, days) {
182
+ const y = v.year, m = v.month, d = v.day;
183
+ const y2 = m <= 2 ? y - 1 : y;
184
+ const era = Math.floor((y2 >= 0 ? y2 : y2 - 399) / 400);
185
+ const yoe = y2 - era * 400;
186
+ const m2 = m > 2 ? m - 3 : m + 9;
187
+ const doy = Math.floor((153 * m2 + 2) / 5) + d - 1;
188
+ const doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
189
+ const totalDays = era * 146097 + doe - 719468 + days;
190
+ const z = totalDays + 719468;
191
+ const era2 = Math.floor((z >= 0 ? z : z - 146096) / 146097);
192
+ const doe2 = z - era2 * 146097;
193
+ const yoe2 = Math.floor((doe2 - Math.floor(doe2 / 1460) + Math.floor(doe2 / 36524) - Math.floor(doe2 / 146096)) / 365);
194
+ const y2out = yoe2 + era2 * 400;
195
+ const doy2 = doe2 - (365 * yoe2 + Math.floor(yoe2 / 4) - Math.floor(yoe2 / 100));
196
+ const mp = Math.floor((5 * doy2 + 2) / 153);
197
+ const d2 = doy2 - Math.floor((153 * mp + 2) / 5) + 1;
198
+ const m2out = mp < 10 ? mp + 3 : mp - 9;
199
+ const yOut = m2out <= 2 ? y2out + 1 : y2out;
200
+ const result = { ...v, year: yOut, month: m2out, day: d2 };
201
+ recomputeDayOfWeek(result);
202
+ return result;
203
+ }
204
+ function shiftTime(v, msDelta) {
205
+ const MS_PER_DAY = 864e5;
206
+ const MS_PER_HOUR = 36e5;
207
+ const MS_PER_MINUTE = 6e4;
208
+ const MS_PER_SECOND = 1e3;
209
+ const totalMs = (v.hour ?? 0) * MS_PER_HOUR + (v.minute ?? 0) * MS_PER_MINUTE + (v.second ?? 0) * MS_PER_SECOND + (v.millisecond ?? 0) + msDelta;
210
+ const dayOverflow = Math.floor(totalMs / MS_PER_DAY);
211
+ let withinDay = totalMs % MS_PER_DAY;
212
+ if (withinDay < 0) {
213
+ withinDay += MS_PER_DAY;
214
+ }
215
+ const hour = Math.floor(withinDay / MS_PER_HOUR);
216
+ const minute = Math.floor(withinDay % MS_PER_HOUR / MS_PER_MINUTE);
217
+ const second = Math.floor(withinDay % MS_PER_MINUTE / MS_PER_SECOND);
218
+ const millisecond = withinDay % MS_PER_SECOND;
219
+ const result = { ...v, hour, minute, second, millisecond };
220
+ if (dayOverflow !== 0) {
221
+ return shiftDays(result, dayOverflow);
222
+ }
223
+ return result;
224
+ }
225
+
226
+ // src/timezone.ts
227
+ function resolveZoned(fields, timeZone, options = {}) {
228
+ const temporal = getTemporal();
229
+ const disambiguation = options.disambiguation ?? "compatible";
230
+ const overflow = options.overflow ?? "constrain";
231
+ const fromOptions = {
232
+ overflow,
233
+ disambiguation,
234
+ offset: options.offset ?? "prefer"
235
+ };
236
+ try {
237
+ return temporal.ZonedDateTime.from(
238
+ {
239
+ year: fields.year,
240
+ month: fields.month,
241
+ day: fields.day,
242
+ hour: fields.hour ?? 0,
243
+ minute: fields.minute ?? 0,
244
+ second: fields.second ?? 0,
245
+ millisecond: fields.millisecond ?? 0,
246
+ microsecond: fields.microsecond ?? 0,
247
+ nanosecond: fields.nanosecond ?? 0,
248
+ timeZone
249
+ },
250
+ fromOptions
251
+ );
252
+ } catch (err) {
253
+ const msg = err.message;
254
+ if (/no such (wall-clock )?time/i.test(msg) && disambiguation === "reject") {
255
+ throw new Error(
256
+ `temporal-fmt: "${timeZone}" has no such wall-clock time on ${fields.year}-${fields.month}-${fields.day}T${fields.hour ?? 0}:${fields.minute ?? 0} \u2014 it falls in a DST gap. Pass { disambiguation: 'compatible' | 'earlier' | 'later' } to pick an instant.`
257
+ );
258
+ }
259
+ throw err;
260
+ }
261
+ }
262
+ function getTimeZone(value) {
263
+ const v = value;
264
+ if (typeof v?.timeZoneId !== "string") {
265
+ throw new Error(`temporal-fmt: getTimeZone() expected a ZonedDateTime, got ${typeof value}.`);
266
+ }
267
+ return v.timeZoneId;
268
+ }
269
+ function getOffset(value) {
270
+ const v = value;
271
+ if (typeof v?.offset !== "string") {
272
+ throw new Error(`temporal-fmt: getOffset() expected a ZonedDateTime, got ${typeof value}.`);
273
+ }
274
+ return v.offset;
275
+ }
276
+ function getOffsetNanoseconds(value) {
277
+ const v = value;
278
+ if (typeof v?.offsetNanoseconds === "number") return v.offsetNanoseconds;
279
+ if (typeof v?.offset === "string") {
280
+ const m = v.offset.match(/^([+-])(\d{2}):(\d{2})$/);
281
+ if (!m) throw new Error(`temporal-fmt: getOffsetNanoseconds() couldn't parse offset "${v.offset}".`);
282
+ const sign = m[1] === "-" ? -1 : 1;
283
+ return sign * (Number(m[2]) * 3600 + Number(m[3]) * 60) * 1e9;
284
+ }
285
+ throw new Error(`temporal-fmt: getOffsetNanoseconds() expected a ZonedDateTime, got ${typeof value}.`);
286
+ }
287
+ function isDST(value) {
288
+ const v = value;
289
+ if (typeof v?.timeZoneId !== "string" || typeof v?.offset !== "string" || typeof v?.year !== "number") {
290
+ throw new Error(`temporal-fmt: isDST() expected a ZonedDateTime, got ${typeof value}.`);
291
+ }
292
+ const temporal = getTemporal();
293
+ try {
294
+ const jan = temporal.ZonedDateTime.from(
295
+ { year: v.year, month: 1, day: 1, hour: 12, timeZone: v.timeZoneId },
296
+ { disambiguation: "compatible" }
297
+ );
298
+ return jan.offset !== v.offset;
299
+ } catch {
300
+ return false;
301
+ }
302
+ }
303
+ function getNextTransition(value) {
304
+ return findTransition(value, 1);
305
+ }
306
+ function getPreviousTransition(value) {
307
+ return findTransition(value, -1);
308
+ }
309
+ function findTransition(value, direction) {
310
+ const v = value;
311
+ if (typeof v?.timeZoneId !== "string") {
312
+ throw new Error(`temporal-fmt: ${direction > 0 ? "getNextTransition" : "getPreviousTransition"}() expected a ZonedDateTime, got ${typeof value}.`);
313
+ }
314
+ const temporal = getTemporal();
315
+ const timeZone = v.timeZoneId;
316
+ let candidateFields = add(value, direction, "days");
317
+ const startOffset = v.offset;
318
+ for (let i = 0; i < 365 * 2; i++) {
319
+ const cf = candidateFields;
320
+ const candidateZdt = temporal.ZonedDateTime.from(
321
+ { ...cf, timeZone },
322
+ { disambiguation: "compatible" }
323
+ );
324
+ if (candidateZdt.offset !== startOffset) {
325
+ return candidateZdt;
326
+ }
327
+ candidateFields = add(candidateFields, direction, "days");
328
+ }
329
+ return void 0;
330
+ }
331
+ function getTransitions(start, end) {
332
+ const result = [];
333
+ const startV = start;
334
+ if (typeof startV?.timeZoneId !== "string") {
335
+ throw new Error(`temporal-fmt: getTransitions() expected a ZonedDateTime for start, got ${typeof start}.`);
336
+ }
337
+ const endV = end;
338
+ const temporal = getTemporal();
339
+ const timeZone = startV.timeZoneId;
340
+ let cursorFields = add(start, 1, "days");
341
+ let lastOffset = startV.offset;
342
+ for (let i = 0; i < 365 * 5; i++) {
343
+ const cf = cursorFields;
344
+ const cursorZdt = temporal.ZonedDateTime.from(
345
+ { ...cf, timeZone },
346
+ { disambiguation: "compatible" }
347
+ );
348
+ if (cursorZdt.offset !== lastOffset) {
349
+ if (cursorZdt.year > endV.year || cursorZdt.year === endV.year && (cursorZdt.month > endV.month || cursorZdt.month === endV.month && cursorZdt.day > endV.day)) break;
350
+ result.push(cursorZdt);
351
+ lastOffset = cursorZdt.offset;
352
+ }
353
+ cursorFields = add(cursorFields, 1, "days");
354
+ }
355
+ return result;
356
+ }
357
+ function possibleInstantsFor(fields, timeZone) {
358
+ const temporal = getTemporal();
359
+ const earlier = temporal.ZonedDateTime.from(
360
+ { ...fields, timeZone },
361
+ { disambiguation: "earlier", offset: "ignore" }
362
+ );
363
+ const later = temporal.ZonedDateTime.from(
364
+ { ...fields, timeZone },
365
+ { disambiguation: "later", offset: "ignore" }
366
+ );
367
+ const matchesRequestedWallClock = (z) => z.year === fields.year && z.month === fields.month && z.day === fields.day && z.hour === fields.hour && z.minute === fields.minute && z.second === fields.second && z.millisecond === fields.millisecond;
368
+ if (!matchesRequestedWallClock(earlier) || !matchesRequestedWallClock(later)) {
369
+ return [];
370
+ }
371
+ if (earlier.toInstant().epochNanoseconds === later.toInstant().epochNanoseconds) {
372
+ return [earlier];
373
+ }
374
+ return [earlier, later];
375
+ }
376
+ // Annotate the CommonJS export names for ESM import in node:
377
+ 0 && (module.exports = {
378
+ getNextTransition,
379
+ getOffset,
380
+ getOffsetNanoseconds,
381
+ getPreviousTransition,
382
+ getTimeZone,
383
+ getTransitions,
384
+ isDST,
385
+ possibleInstantsFor,
386
+ resolveZoned
387
+ });
21
388
  //# sourceMappingURL=timezone.cjs.map