@zodiacs/engine 0.1.1-rc.14 → 0.1.1-rc.15
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/CHANGELOG.md +364 -6
- package/LICENSING.md +180 -14
- package/NOTICE +73 -9
- package/README.md +116 -69
- package/dist/api-CoB_kqE3.d.ts +198 -0
- package/dist/chunk-CWI4YUDL.js +355 -0
- package/dist/chunk-KFTJMMG7.js +61 -0
- package/dist/chunk-KHBLFXFG.js +227 -0
- package/dist/{chunk-NAJ735VN.js → chunk-MFF3VKO3.js} +1 -1
- package/dist/chunk-OYGRVGXD.js +25 -0
- package/dist/{chunk-4OSOCZY2.js → chunk-ZHVI3KWJ.js} +21 -6
- package/dist/{chunk-RETEVD4F.js → chunk-ZZPITHQS.js} +115 -110
- package/dist/crossings.d.ts +1 -1
- package/dist/deltat.d.ts +8 -8
- package/dist/geo.d.ts +137 -8
- package/dist/geo.js +414 -109
- package/dist/index.d.ts +7 -201
- package/dist/index.js +28 -305
- package/dist/{internal-math-BE2hcSHd.d.ts → internal-math-BbktkHCc.d.ts} +14 -1
- package/dist/internal-math.d.ts +2 -2
- package/dist/internal-math.js +2 -2
- package/dist/internal.d.ts +2 -1
- package/dist/internal.js +4 -4
- package/dist/receipt.d.ts +56 -36
- package/dist/receipt.js +188 -33
- package/dist/timing.d.ts +414 -0
- package/dist/timing.js +851 -0
- package/dist/{types-CeafogFp.d.ts → types-BsWaqwU_.d.ts} +35 -4
- package/dist/tzdb-2025c-00-6GVG6RYL.js +6 -0
- package/dist/tzdb-2025c-01-CEYMG3LE.js +6 -0
- package/dist/tzdb-2025c-02-NWQJCVUU.js +6 -0
- package/dist/tzdb-2025c-03-PLHP6VH4.js +6 -0
- package/dist/tzdb-2025c-04-MEKUJA6M.js +6 -0
- package/dist/tzdb-2025c-05-3K5YKZBL.js +6 -0
- package/dist/tzdb-2025c-06-L2VV5XJV.js +6 -0
- package/dist/tzdb-2025c-07-H3GLGJGY.js +6 -0
- package/dist/tzdb-2025c-08-DA7QQIGD.js +6 -0
- package/dist/tzdb-2025c-09-MTXIO3QL.js +6 -0
- package/dist/tzdb-2025c-10-ASL4UW5C.js +6 -0
- package/dist/tzdb-2025c-11-EQEOANYB.js +6 -0
- package/dist/tzdb-2025c-12-NKCCXJ5G.js +6 -0
- package/dist/tzdb-2025c-13-DYTF3UC7.js +6 -0
- package/dist/tzdb-2025c-14-C25H45R5.js +6 -0
- package/dist/tzdb-2025c-15-7OYYZWRY.js +6 -0
- package/dist/vedic.d.ts +394 -0
- package/dist/vedic.js +947 -0
- package/package.json +11 -3
- package/dist/chunk-GFT24GFR.js +0 -25
package/dist/geo.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
civilDateOf,
|
|
3
|
+
format,
|
|
4
|
+
gregorianToJulian,
|
|
5
|
+
julianDayNumber,
|
|
6
|
+
julianToGregorian,
|
|
7
|
+
parseCalendarDate
|
|
8
|
+
} from "./chunk-KFTJMMG7.js";
|
|
1
9
|
import {
|
|
2
10
|
validateBirthSettings
|
|
3
11
|
} from "./chunk-PFGUCNOK.js";
|
|
@@ -142,9 +150,184 @@ function createGeoNamesClient(options) {
|
|
|
142
150
|
};
|
|
143
151
|
}
|
|
144
152
|
|
|
153
|
+
// src/geo/calendar.ts
|
|
154
|
+
var GREGORIAN_ADOPTION_SOURCES = Object.freeze({
|
|
155
|
+
tzdb: "IANA tzdata 2025c, file calendars, quoting H. Grotefend, Taschenbuch der Zeitrechnung, ed. O. Grotefend (1941), pp. 26-28",
|
|
156
|
+
"grotefend-1891": "H. Grotefend, Zeitrechnung des deutschen Mittelalters und der Neuzeit, vol. 1 (1891), pp. 133-134",
|
|
157
|
+
"grotefend-1898": "H. Grotefend, Taschenbuch der Zeitrechnung des deutschen Mittelalters und der Neuzeit (1898), pp. 23-24"
|
|
158
|
+
});
|
|
159
|
+
var ROWS = `AT|Austria|Austria|1584-01-17|t|Grotefend 1898: 1583-10-16, with Bavaria. Salzburg 1583-10-16; Styria 1583-12-25.
|
|
160
|
+
BE|Belgium|Brabant, Flanders, Hainaut|1583-01-01|t|Grotefend 1891, 1898: 1582-12-25. Bishopric of Li\xE8ge 1583-02-21.
|
|
161
|
+
CH|Switzerland|Z\xFCrich, Bern, Basel, Schaffhausen|1701-01-12|t18|Also Geneva and Thurgau. Catholic cantons 1584-01-22 (Grotefend 1891: 1584-01-23); Unterwalden June 1584; Glarus, Appenzell, St. Gallen city 1724; Valais 1655 (Grotefend 1898: 1622); Graub\xFCnden 1760-1812 (Grotefend 1898: to 1811); bishopric of Basel 1583-10-31.
|
|
162
|
+
CZ|Czech Republic|Bohemia|1584-01-17|t18|Silesia 1584-01-23. Moravia is not dated.
|
|
163
|
+
DE|Germany|Protestant states|1700-03-01|t18|Catholic states from 1583: bishopric of Augsburg 1583-02-24, Bavaria 1583-10-16, the latest listed the bishopric of Hildesheim 1631-03-26.
|
|
164
|
+
DK|Denmark|-|1700-03-01|t18|
|
|
165
|
+
ES|Spain|-|1582-10-15|t18|
|
|
166
|
+
FI|Finland|-|1753-03-01|t|With Sweden; see Sweden. tzdb's list says the Russian empire, Finland included, kept the Julian calendar until 1917.
|
|
167
|
+
FR|France|France, Lorraine|1582-12-20|t18|City of Strasbourg 1682-02-16; bishopric of Strasbourg 1583-11-27 (Grotefend 1898: 1583-11-22); Austrian Upper Alsace 1583-10-24. Republican calendar 1793-11-24 to 1805-12-31, in Paris also 1871-05-06 to 1871-05-23: not converted.
|
|
168
|
+
GB|Britain (UK)|Great Britain|1752-09-14|t18|
|
|
169
|
+
HU|Hungary|-|1587-11-01|t18|The legal change. tzdb's list also gives 1584-02-02, "legally on 21 Oct 1587".
|
|
170
|
+
IT|Italy|Italy, with exceptions|1582-10-15|t18|Bishopric of Brixen (Bressanone) 1583-10-16.
|
|
171
|
+
NL|Netherlands|Holland|1583-01-01|t|Grotefend 1891, 1898: 1582-12-25. Gelderland 1700-07-12; Zutphen 1700-07-12 (Grotefend 1898: 1700-12-12); Utrecht, Overijssel 1700-12-12; Friesland, Groningen 1701-01-12; Grotefend 1891: 1700-12-12 for all six. Zeeland and Drenthe are not dated.
|
|
172
|
+
NO|Norway|-|1700-03-01|t|Grotefend 1891, 1898 name Denmark only.
|
|
173
|
+
PL|Poland|Roman Catholics, and Danzig|1582-10-15|t|Grotefend 1898: not everywhere, notably not among Protestants and the Greek Church; Grotefend 1891: 1586. Silesia 1584-01-23; duchy of Prussia 1612-09-02 (Grotefend 1898: 1612-09-01).
|
|
174
|
+
PT|Portugal|-|1582-10-15|t18|
|
|
175
|
+
RU|Russia|Soviet Russia|1918-02-14|t|Grotefend 1891, 1898: still Julian. Duchy of Prussia, now partly Kaliningrad, 1612-09-02 (Grotefend 1898: 1612-09-01).
|
|
176
|
+
SE|Sweden|-|1753-03-01|t18|From 1 March 1700 to 30 February 1712 Swedish dates are one day ahead of the Julian (Grotefend 1898).`;
|
|
177
|
+
var SOURCE_KEYS = { t: "tzdb", 1: "grotefend-1891", 8: "grotefend-1898" };
|
|
178
|
+
var GREGORIAN_ADOPTION = Object.freeze(
|
|
179
|
+
ROWS.split("\n").map((line) => {
|
|
180
|
+
const [code, country, region, firstGregorian, sources, note] = line.split("|");
|
|
181
|
+
const day = julianDayNumber(parseCalendarDate(firstGregorian, "gregorian"), "gregorian");
|
|
182
|
+
return Object.freeze({
|
|
183
|
+
code,
|
|
184
|
+
country,
|
|
185
|
+
region: region === "-" ? null : region,
|
|
186
|
+
firstGregorian,
|
|
187
|
+
lastJulian: format(civilDateOf(day - 1, "julian")),
|
|
188
|
+
sources: Object.freeze([...sources].map((key) => SOURCE_KEYS[key])),
|
|
189
|
+
note
|
|
190
|
+
});
|
|
191
|
+
})
|
|
192
|
+
);
|
|
193
|
+
function gregorianAdoption(country) {
|
|
194
|
+
return GREGORIAN_ADOPTION.find((row) => row.code === country || row.country === country);
|
|
195
|
+
}
|
|
196
|
+
function calendarNote(gregorianDate, calendar, country) {
|
|
197
|
+
const adoption = gregorianAdoption(country);
|
|
198
|
+
if (!adoption) return null;
|
|
199
|
+
const julian = calendar === "julian";
|
|
200
|
+
if (gregorianDate >= adoption.firstGregorian) return julian ? { kind: "new-style", adoption } : null;
|
|
201
|
+
return julian ? null : { kind: "old-style", adoption };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/tzdb/tzdb-2025c.ts
|
|
205
|
+
var TZDB = Object.freeze({
|
|
206
|
+
version: "2025c",
|
|
207
|
+
sha256: "4aa79e4effee53fc4029ffe5f6ebe97937282ebcdf386d5d2da91ce84142f957",
|
|
208
|
+
form: "main+backzone"
|
|
209
|
+
});
|
|
210
|
+
var SHARD_LOADERS = [
|
|
211
|
+
() => import("./tzdb-2025c-00-6GVG6RYL.js"),
|
|
212
|
+
() => import("./tzdb-2025c-01-CEYMG3LE.js"),
|
|
213
|
+
() => import("./tzdb-2025c-02-NWQJCVUU.js"),
|
|
214
|
+
() => import("./tzdb-2025c-03-PLHP6VH4.js"),
|
|
215
|
+
() => import("./tzdb-2025c-04-MEKUJA6M.js"),
|
|
216
|
+
() => import("./tzdb-2025c-05-3K5YKZBL.js"),
|
|
217
|
+
() => import("./tzdb-2025c-06-L2VV5XJV.js"),
|
|
218
|
+
() => import("./tzdb-2025c-07-H3GLGJGY.js"),
|
|
219
|
+
() => import("./tzdb-2025c-08-DA7QQIGD.js"),
|
|
220
|
+
() => import("./tzdb-2025c-09-MTXIO3QL.js"),
|
|
221
|
+
() => import("./tzdb-2025c-10-ASL4UW5C.js"),
|
|
222
|
+
() => import("./tzdb-2025c-11-EQEOANYB.js"),
|
|
223
|
+
() => import("./tzdb-2025c-12-NKCCXJ5G.js"),
|
|
224
|
+
() => import("./tzdb-2025c-13-DYTF3UC7.js"),
|
|
225
|
+
() => import("./tzdb-2025c-14-C25H45R5.js"),
|
|
226
|
+
() => import("./tzdb-2025c-15-7OYYZWRY.js")
|
|
227
|
+
];
|
|
228
|
+
var LATER_CAUSES = "26z1v3r9wo.2lzdo.2092c.51mzc.;4omh4gkhm0.;8i4hw7ji4c.8fno.94cvo.;emnzt8v8m6.;pibsacwtc0.;shzcp6wjs0.609ic.14eec.;qn9anc1rqo.;hr04d6wjeo.609ic.14eec.;iwfdj6f1oo.;jxme485390.;vxtl73htjc.;zmgwf7egs0!;008wxcglro.4g1o.ie6c.3m1o.;xgck2d5eqc!;x90aj50d2u.;e4lpj23xc0.;n97c09emgo.6l9mc.;c1i1b2i6cc.;srkypcglq0.4970.il10.3lyc.1glac.fl5o.6hh0.4ypc.67h0.4t70.6hc1.4yqz.69p1.4yqz.69p1.4vjz.;6bx5p6nh2c.69c80.14eec.fzlo.;d7foo4bvj0.;da48bez4xo.;cc60723xc0.;r2ctm3r9wo.2lzdo.2092c.51mzc.;09xrhgo29o.;23q2c4g4g0.;2fq0m6nh2c.69c80.14eec.nrlo.;73ubg6wji0.609ic.14eec.;glme93r9mo.;iztuh9nq0c.;yksj0kmbc.;94mmz6nh2c.69c80.14eec.195lo.oeuc.;c9gx56mm3c.74rc.3y7yc.l5o.;ftdfk2i6cc.;fyvor6f1oo.;oqbaz9c9u0.;upch43ip7c.;4tlos3ofjo.38450.;bzp0f6wjn0.8fhf0.;cwffa6mm3c.74rc.;lal8k92wc0.;oyxuu31w40.4rwuc!;z0hat2fygi.bwwu.;091etgo29o.;blqvj6wjlc.f49c.5l5ao.14eec.jnto.;tgp36clt30.;9wqor23xc0.;vma32kmbc.;6vjgid5eoo!;agkxx6wji0.609ic.14eec.fznc.;bt63w1yu1o.;6fyvm6dbgo.;93ycg6f1oo.;jenq11pdmo.;kikwv6wjjo.609ic.14eec.;6i87mkmbc.;ktr4c6bdnc.tlnc.3mpic.3w1o.;lnqdp1pdmo.;x5jk0173j0.;ylrpy4bvj0.;yvsdoecogo.10ao0.;51sa56mm3c.74rc.3y7yc.l5o.;imjhpc1rsc.1onac.;xgvkj6tqo0.632mc.;4rg6l6wjd0.609k0.;cx7tr6mm3c.74rc.;e7mcw6wjlc.609ic.14eec.;3se9a6dbgo.;8k2bmkmbc.;nkww16bdnc.hxnc.;sjll11ibsc.856ho.12w0.;tbefcc1rsc.1onac.;v730i4n7yc.;dvg44kmbc.;v977f6mm3c.74rc.3y7yc.ddo.;7egrqe35eo.;lgxqt4g4g0.k8uc.;8hz4v6mm3c.74rc.3y7yc.l5o.;pyva5q8v0.;npf8s6wjn0.a2170.;x1w033is10.3drdo.609ic.58r0.z5p0.;068n925yo0.;kjcdu4m9pu.;b0ken2i6e0.;e0yew2i6cc.;pfxgu6wjn0.609ic.14eec.;4oapw3r3pc.9lic.;9linmuzqo.gvqc.;z70s311v0q6_;zme5q6wjoo.a215c.;oh15y11je0.k8uc.5a80c.88fo.321o.193ac.;blv5h6mjvc.22jc.43cec.l5o.;d7hxtkmbc.;jvnzr6f1oo.;wrz6f32nac.h2ho.;x7xki3r9mo.;0aanqasrbo.8fio.;foc486wjoo.609ic.14eec.;wh9055mw2o.;04yj4kmbc.;31xyt6wjeo.609ic.14eec.gurc.;k0dlb4n7yc.;k4x616wjeo.609k0.14eec.fzlo.;qsklxf141o.b9k0.;d90416wjlc.11sxc.4ygmo.14eec.fzlo.;diqxz9emgo.5klmc.;hqu65r7tc.;r60tt9c9u0.;7hozj7egs0!;n4f883r3pc.bjf0.4vl5o.560rc.;rcx29bn8lc.;tyfb56wjoo.;3mwwdr7tc.;h2j0f6wjoo.;n3exs6wjgc.609ic.14eec.;pf3zccwtc0.14eec.;3wlms4692o.8kazc.;hjhq6852vo.;yded86mm3c.74rc.;cshzubvnvo.2mmo0.;mkxe53htjc.;u226p6mm3c.74rc.;v8ck8774zc.5b2c.;xy1qbcgltc.;s3w2g3ofjo.38450.u8uc.;58co631w1s.4rwuw!;x8ghc1uhio.;y3thu2fygi.bwwu.;u3e1j1qwm9.57t4f.;cga095k1yu.;7xj8c6wjs0.609ic.14eec.;5m66y6wjlc.37w6c.2sddo.14eec.hxlo.;69icl31w40.4rwuc!;mu12m6bdnc.tlnc.3mpic.3w1o.;odp3marwl0.ndo.;otx0189jyu.4r36.2yq8u.;sxc0n6nh2c.69c80.14eec.;mez0y6wjoo.;tsxgk3r9mo.;2447s1zep0.7ms9o.;3s5e6c1rsc.1onac.;983km2uo86.;qbuhn50d2u.;qslwbe5bvo.;u0hxf6wji0.3qpv0.29jlo.58r0.z5p0.;cft6i6borc.dpfc.42jic.1p5o.13cko.jezc.;6o3pl3uzh0.;ertoo6wjs0.609ic.14eec.fzlo.;h5uvn5k1yu.;sa6yk50dkc.;4q92r6bdnc.hxnc.;wfyr46wjoo.;7zfow2rx5i.;j06xje5c0o.;teiet4bvo0.;6v8ej6mjvc.22jc.43bac.1p5o.;ajtnw2x3so.;ttwf6ea8x0.uog0.;o6n0f6wjlc.609k0.;4bqjbaryt0.l5o.;j9sdo38geo.;0hdnqebsg6.;6qmtw6f1qc.177go.68h90.6h8o.;asm1e4n7yc.;kzndtc1rsc.1onac.;mmp3d1kcxo.;pjzkh6wjd0.609k0.";
|
|
229
|
+
|
|
230
|
+
// src/geo/zone-history.ts
|
|
231
|
+
var CAUSES = { d: "dst", l: "legal-change", x: "date-line" };
|
|
232
|
+
function nameHash(name) {
|
|
233
|
+
const key = name.toLowerCase();
|
|
234
|
+
let hash = 2166136261;
|
|
235
|
+
for (let index = 0; index < key.length; index += 1) {
|
|
236
|
+
hash ^= key.charCodeAt(index);
|
|
237
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
238
|
+
}
|
|
239
|
+
return hash;
|
|
240
|
+
}
|
|
241
|
+
function decode(entry) {
|
|
242
|
+
const times = [];
|
|
243
|
+
let previous = 0;
|
|
244
|
+
if (entry.t) {
|
|
245
|
+
entry.t.split(",").forEach((part, index) => {
|
|
246
|
+
const value = parseInt(part, 36);
|
|
247
|
+
previous = index === 0 ? value : previous + value;
|
|
248
|
+
times.push(previous * 1e3);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
const types = [0];
|
|
252
|
+
const causes = [];
|
|
253
|
+
for (let index = 0; index < entry.k.length; index += 2) {
|
|
254
|
+
types.push(parseInt(entry.k[index], 36));
|
|
255
|
+
causes.push(CAUSES[entry.k[index + 1]]);
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
name: entry.n,
|
|
259
|
+
source: entry.s,
|
|
260
|
+
hostLegal: entry.h === 1,
|
|
261
|
+
zoneEraEnd: entry.f === null ? null : entry.f * 1e3,
|
|
262
|
+
era: entry.e ? entry.e.map(([until, offset]) => [until * 1e3, offset]) : null,
|
|
263
|
+
times,
|
|
264
|
+
types,
|
|
265
|
+
causes,
|
|
266
|
+
offsets: entry.y.map((type) => type[0]),
|
|
267
|
+
dst: entry.y.map((type) => type[1] === 1),
|
|
268
|
+
abbreviations: entry.y.map((type) => type[2])
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
var histories = /* @__PURE__ */ new Map();
|
|
272
|
+
var loads = /* @__PURE__ */ new Map();
|
|
273
|
+
function loadedHistory(timeZone) {
|
|
274
|
+
return histories.get(timeZone.toLowerCase());
|
|
275
|
+
}
|
|
276
|
+
function loadHistory(timeZone) {
|
|
277
|
+
const key = timeZone.toLowerCase();
|
|
278
|
+
if (histories.has(key)) return Promise.resolve();
|
|
279
|
+
const bucket = nameHash(timeZone) % SHARD_LOADERS.length;
|
|
280
|
+
let pending = loads.get(bucket);
|
|
281
|
+
if (!pending) {
|
|
282
|
+
const load = SHARD_LOADERS[bucket]().then((module) => module.default);
|
|
283
|
+
loads.set(bucket, load);
|
|
284
|
+
void load.catch(() => {
|
|
285
|
+
if (loads.get(bucket) === load) loads.delete(bucket);
|
|
286
|
+
});
|
|
287
|
+
pending = load;
|
|
288
|
+
}
|
|
289
|
+
const ready = pending.then((zones) => {
|
|
290
|
+
const entry = Object.prototype.hasOwnProperty.call(zones, key) ? zones[key] : void 0;
|
|
291
|
+
histories.set(key, entry ? decode(entry) : null);
|
|
292
|
+
});
|
|
293
|
+
void ready.catch(() => {
|
|
294
|
+
});
|
|
295
|
+
return ready;
|
|
296
|
+
}
|
|
297
|
+
function typeIndexAt(history, ms) {
|
|
298
|
+
let lo = 0;
|
|
299
|
+
let hi = history.times.length;
|
|
300
|
+
while (lo < hi) {
|
|
301
|
+
const mid = lo + hi >> 1;
|
|
302
|
+
if (history.times[mid] <= ms) lo = mid + 1;
|
|
303
|
+
else hi = mid;
|
|
304
|
+
}
|
|
305
|
+
return lo;
|
|
306
|
+
}
|
|
307
|
+
function transitionAt(history, ms) {
|
|
308
|
+
const index = typeIndexAt(history, ms) - 1;
|
|
309
|
+
return index >= 0 && history.times[index] === ms ? index : -1;
|
|
310
|
+
}
|
|
311
|
+
var later;
|
|
312
|
+
function laterCause(timeZone, ms) {
|
|
313
|
+
if (!later) {
|
|
314
|
+
later = /* @__PURE__ */ new Map();
|
|
315
|
+
for (const row of LATER_CAUSES.split(";")) {
|
|
316
|
+
const causes = /* @__PURE__ */ new Map();
|
|
317
|
+
let at = 0;
|
|
318
|
+
for (const [, digits, mark] of row.slice(5).matchAll(/([0-9a-z]+)([.!_~])/g)) {
|
|
319
|
+
const kind = ".!_~".indexOf(mark);
|
|
320
|
+
at += parseInt(digits, 36) * (kind < 2 ? 6e4 : 1e3);
|
|
321
|
+
causes.set(at, kind % 2 ? "date-line" : "legal-change");
|
|
322
|
+
}
|
|
323
|
+
later.set(parseInt(row.slice(0, 5), 36), causes);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return later.get(nameHash(timeZone) % 36 ** 5)?.get(ms) ?? "dst";
|
|
327
|
+
}
|
|
328
|
+
|
|
145
329
|
// src/geo/timezone.ts
|
|
146
330
|
var offsetFormatters = /* @__PURE__ */ new Map();
|
|
147
|
-
var wallFormatters = /* @__PURE__ */ new Map();
|
|
148
331
|
function validateTimeZone(timeZone) {
|
|
149
332
|
if (typeof timeZone !== "string" || timeZone.trim().length === 0) {
|
|
150
333
|
throw new RangeError("timeZone must be an explicit nonempty timezone string.");
|
|
@@ -164,32 +347,13 @@ function offsetFormatter(timeZone) {
|
|
|
164
347
|
}
|
|
165
348
|
return formatter;
|
|
166
349
|
}
|
|
167
|
-
function
|
|
168
|
-
validateTimeZone(timeZone);
|
|
169
|
-
let formatter = wallFormatters.get(timeZone);
|
|
170
|
-
if (!formatter) {
|
|
171
|
-
formatter = new Intl.DateTimeFormat("en-US", {
|
|
172
|
-
timeZone,
|
|
173
|
-
calendar: "gregory",
|
|
174
|
-
numberingSystem: "latn",
|
|
175
|
-
era: "short",
|
|
176
|
-
year: "numeric",
|
|
177
|
-
month: "2-digit",
|
|
178
|
-
day: "2-digit",
|
|
179
|
-
hour: "2-digit",
|
|
180
|
-
minute: "2-digit",
|
|
181
|
-
second: "2-digit",
|
|
182
|
-
fractionalSecondDigits: 3,
|
|
183
|
-
hourCycle: "h23"
|
|
184
|
-
});
|
|
185
|
-
wallFormatters.set(timeZone, formatter);
|
|
186
|
-
}
|
|
187
|
-
return formatter;
|
|
188
|
-
}
|
|
189
|
-
function offsetAt(timeZone, utcMilliseconds) {
|
|
350
|
+
function validateInstant(utcMilliseconds) {
|
|
190
351
|
if (typeof utcMilliseconds !== "number" || !Number.isFinite(utcMilliseconds)) {
|
|
191
352
|
throw new RangeError("utcMilliseconds must be a finite epoch-millisecond timestamp.");
|
|
192
353
|
}
|
|
354
|
+
}
|
|
355
|
+
function offsetAt(timeZone, utcMilliseconds) {
|
|
356
|
+
validateInstant(utcMilliseconds);
|
|
193
357
|
const name = offsetFormatter(timeZone).formatToParts(utcMilliseconds).find((part) => part.type === "timeZoneName")?.value;
|
|
194
358
|
const match = (name ?? "GMT").match(/^GMT(?:([+-])(\d{1,2})(?::(\d{2}))?(?::(\d{2}))?)?$/u);
|
|
195
359
|
if (!match) {
|
|
@@ -198,115 +362,256 @@ function offsetAt(timeZone, utcMilliseconds) {
|
|
|
198
362
|
const sign = match[1] === "-" ? -1 : 1;
|
|
199
363
|
return sign * (Number(match[2] ?? 0) * 60 + Number(match[3] ?? 0) + Number(match[4] ?? 0) / 60);
|
|
200
364
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
365
|
+
var DAY = 864e5;
|
|
366
|
+
var PROBE = 36 * 36e5;
|
|
367
|
+
var MAX_DEPARTURE_SECONDS = 180 * 60;
|
|
368
|
+
var FIXED_ZONE = /^(?:etc\/)?(?:utc|uct|gmt|gmt0|gmt[+-]0|greenwich|universal|zulu)$|^etc\/gmt[+-]\d{1,2}$/iu;
|
|
369
|
+
function hostTzdbVersion() {
|
|
370
|
+
const tz = globalThis.process?.versions?.tz;
|
|
371
|
+
return typeof tz === "string" && /^\d{4}[a-z]$/u.test(tz) ? tz : null;
|
|
372
|
+
}
|
|
373
|
+
function firstChange(clockAt, lo, hi) {
|
|
374
|
+
const from = clockAt(lo);
|
|
375
|
+
while (hi - lo > 1) {
|
|
376
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
377
|
+
if (clockAt(mid) === from) lo = mid;
|
|
378
|
+
else hi = mid;
|
|
207
379
|
}
|
|
208
|
-
|
|
209
|
-
const isoYear = year >= 0 && year <= 9999 ? String(year).padStart(4, "0") : `${year < 0 ? "-" : "+"}${String(Math.abs(year)).padStart(6, "0")}`;
|
|
210
|
-
return `${isoYear}-${part("month").padStart(2, "0")}-${part("day").padStart(2, "0")}T${part("hour").padStart(2, "0")}:${part("minute").padStart(2, "0")}:${part("second").padStart(2, "0")}.${part("fractionalSecond").padStart(3, "0")}`;
|
|
380
|
+
return hi;
|
|
211
381
|
}
|
|
212
|
-
function
|
|
213
|
-
|
|
214
|
-
|
|
382
|
+
function readClock(wallMs, clockAt, samples) {
|
|
383
|
+
const readings = [];
|
|
384
|
+
for (const offset of new Set(samples.map(clockAt))) {
|
|
385
|
+
const utcMs2 = wallMs - offset * 1e3;
|
|
386
|
+
if (clockAt(utcMs2) === offset && !readings.some((reading) => reading.utcMs === utcMs2)) {
|
|
387
|
+
readings.push({ utcMs: utcMs2, offset });
|
|
388
|
+
}
|
|
215
389
|
}
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
throw new RangeError("Local date/time must use YYYY-MM-DD and HH:MM.");
|
|
390
|
+
const [first, second] = readings.sort((a, b) => a.utcMs - b.utcMs);
|
|
391
|
+
if (first) {
|
|
392
|
+
return second ? { chosen: first, kind: "fold", at: firstChange(clockAt, first.utcMs, second.utcMs) } : { chosen: first, kind: null, at: null };
|
|
220
393
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
throw new RangeError("Local date/time contains an out-of-range field.");
|
|
394
|
+
let lo = wallMs - PROBE - DAY;
|
|
395
|
+
let hi = wallMs + PROBE + DAY;
|
|
396
|
+
while (hi - lo > 1) {
|
|
397
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
398
|
+
if (mid + clockAt(mid) * 1e3 > wallMs) hi = mid;
|
|
399
|
+
else lo = mid;
|
|
228
400
|
}
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
401
|
+
const utcMs = wallMs - clockAt(lo) * 1e3;
|
|
402
|
+
return { chosen: { utcMs, offset: clockAt(utcMs) }, kind: "gap", at: hi };
|
|
403
|
+
}
|
|
404
|
+
function zoneClock(timeZone, history) {
|
|
405
|
+
return (ms) => {
|
|
406
|
+
const offset = history && ms < 0 ? history.offsets[history.types[typeIndexAt(history, ms)]] : null;
|
|
407
|
+
return offset ?? Math.round(offsetAt(timeZone, ms) * 60);
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function birthplaceClock(history, wallMs, longitude, zoneAt) {
|
|
411
|
+
const era = history.era;
|
|
412
|
+
if (!era) return null;
|
|
413
|
+
const endMs = era[era.length - 1][0];
|
|
414
|
+
if (wallMs - PROBE > endMs) return null;
|
|
415
|
+
const meanSeconds = Math.round(longitude * 240);
|
|
416
|
+
const eraOffset = (ms) => (era.find(([until]) => ms < until) ?? era[era.length - 1])[1];
|
|
417
|
+
const place = (ms) => meanSeconds + Math.round((eraOffset(ms) - meanSeconds) / 86400) * 86400;
|
|
418
|
+
const sample = Math.min(wallMs, endMs - 1);
|
|
419
|
+
if (Math.abs(place(sample) - eraOffset(sample)) > MAX_DEPARTURE_SECONDS) return null;
|
|
420
|
+
const legalFrom = history.hostLegal && zoneAt(endMs + PROBE) !== zoneAt(endMs) ? firstChange(zoneAt, endMs, endMs + PROBE) : endMs;
|
|
421
|
+
return {
|
|
422
|
+
clockAt: (ms) => ms < endMs ? place(ms) : zoneAt(Math.max(ms, legalFrom)),
|
|
423
|
+
endMs,
|
|
424
|
+
legalFrom,
|
|
425
|
+
/** The era's own line ends before endMs: moves across the date line. */
|
|
426
|
+
lineEnds: era.slice(0, -1).map(([until]) => until)
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function readOptions(options) {
|
|
430
|
+
if (options === void 0) return { calendar: "gregorian" };
|
|
431
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
432
|
+
throw new RangeError("options must be an object.");
|
|
234
433
|
}
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
function resolveLocalToUtc(date, time, timeZone) {
|
|
238
|
-
const localMilliseconds = wallMilliseconds(date, time);
|
|
239
|
-
const wall = `${date}T${time}:00.000`;
|
|
240
|
-
const sampledOffsets = [
|
|
241
|
-
offsetAt(timeZone, localMilliseconds - 36 * 36e5),
|
|
242
|
-
offsetAt(timeZone, localMilliseconds),
|
|
243
|
-
offsetAt(timeZone, localMilliseconds + 36 * 36e5)
|
|
244
|
-
];
|
|
245
|
-
const candidates = [...new Set(sampledOffsets)];
|
|
246
|
-
const matches = [];
|
|
247
|
-
for (const offset of candidates) {
|
|
248
|
-
const utcMilliseconds = localMilliseconds - Math.round(offset * 6e4);
|
|
249
|
-
if (wallStringAt(timeZone, utcMilliseconds) === wall) {
|
|
250
|
-
matches.push({
|
|
251
|
-
utcMilliseconds,
|
|
252
|
-
offset: offsetAt(timeZone, utcMilliseconds)
|
|
253
|
-
});
|
|
254
|
-
}
|
|
434
|
+
for (const key of Object.getOwnPropertyNames(options)) {
|
|
435
|
+
if (!["longitude", "calendar", "country"].includes(key)) throw new RangeError(`Unknown local time option "${key}".`);
|
|
255
436
|
}
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
437
|
+
const { longitude, calendar = "gregorian", country } = options;
|
|
438
|
+
if (longitude !== void 0 && !(typeof longitude === "number" && Math.abs(longitude) <= 180)) {
|
|
439
|
+
throw new RangeError("longitude must be between -180 and 180 degrees.");
|
|
440
|
+
}
|
|
441
|
+
if (calendar !== "gregorian" && calendar !== "julian") throw new RangeError('calendar must be "gregorian" or "julian".');
|
|
442
|
+
if (country !== void 0 && (typeof country !== "string" || !country.trim())) {
|
|
443
|
+
throw new RangeError("country must be a nonempty string.");
|
|
444
|
+
}
|
|
445
|
+
return { longitude, calendar, country };
|
|
446
|
+
}
|
|
447
|
+
var pad = (value, width = 2) => String(value).padStart(width, "0");
|
|
448
|
+
function resolveLocalToUtc(date, time, timeZone, options) {
|
|
449
|
+
offsetFormatter(timeZone);
|
|
450
|
+
const { longitude, calendar, country } = readOptions(options);
|
|
451
|
+
const written = parseCalendarDate(date, calendar);
|
|
452
|
+
const hhmm = typeof time === "string" ? /^([01]\d|2[0-3]):([0-5]\d)$/u.exec(time) : null;
|
|
453
|
+
if (!written || !hhmm) {
|
|
454
|
+
throw new RangeError(`Local date/time must be a ${calendar === "julian" ? "Julian" : "Gregorian"} date YYYY-MM-DD and a time HH:MM.`);
|
|
455
|
+
}
|
|
456
|
+
const civil = calendar === "julian" ? civilDateOf(julianDayNumber(written, "julian"), "gregorian") : written;
|
|
457
|
+
if (civil.year < 0) throw new RangeError("The Julian date falls before the Gregorian year 0000.");
|
|
458
|
+
const gregorianDate = `${pad(civil.year, 4)}-${pad(civil.month)}-${pad(civil.day)}`;
|
|
459
|
+
const wall = /* @__PURE__ */ new Date(0);
|
|
460
|
+
wall.setUTCFullYear(civil.year, civil.month - 1, civil.day);
|
|
461
|
+
const wallMs = wall.setUTCHours(Number(hhmm[1]), Number(hhmm[2]));
|
|
462
|
+
const loaded = FIXED_ZONE.test(timeZone) ? null : loadedHistory(timeZone);
|
|
463
|
+
if (loaded === void 0 && wallMs < DAY) throw notLoaded();
|
|
464
|
+
const history = loaded ?? null;
|
|
465
|
+
const zoneAt = zoneClock(timeZone, history);
|
|
466
|
+
const place = longitude !== void 0 && history ? birthplaceClock(history, wallMs, longitude, zoneAt) : null;
|
|
467
|
+
const samples = [wallMs - PROBE, wallMs, wallMs + PROBE, ...place ? [place.endMs - 1, place.endMs, place.legalFrom] : []];
|
|
468
|
+
const clockAt = place ? place.clockAt : zoneAt;
|
|
469
|
+
const zoneReading = readClock(wallMs, zoneAt, samples);
|
|
470
|
+
const reading = place ? readClock(wallMs, clockAt, samples) : zoneReading;
|
|
471
|
+
const { chosen, kind } = reading;
|
|
472
|
+
const inEra = !!place && chosen.utcMs < place.endMs;
|
|
473
|
+
const count = history && chosen.utcMs < 0 ? typeIndexAt(history, chosen.utcMs) : -1;
|
|
474
|
+
const type = count < 0 ? -1 : history.types[count];
|
|
475
|
+
const shipped = inEra || type >= 0 && history.offsets[type] !== null;
|
|
476
|
+
let applied = reading.at;
|
|
477
|
+
if (applied === null && shipped) {
|
|
478
|
+
const recorded = count > 0 ? history.times[count - 1] : null;
|
|
479
|
+
const marks = place ? [...place.lineEnds, place.endMs, place.legalFrom].filter((at) => at <= chosen.utcMs) : [];
|
|
480
|
+
if (recorded !== null && (!place || recorded >= place.legalFrom)) marks.push(recorded);
|
|
481
|
+
applied = marks.length ? Math.max(...marks) : null;
|
|
482
|
+
}
|
|
483
|
+
let transition = null;
|
|
484
|
+
if (applied !== null) {
|
|
485
|
+
const at = applied;
|
|
486
|
+
const before = clockAt(at - 1);
|
|
487
|
+
const after = clockAt(at);
|
|
488
|
+
const recorded = history && at < 0 ? transitionAt(history, at) : -1;
|
|
489
|
+
transition = {
|
|
490
|
+
at: new Date(at).toISOString(),
|
|
491
|
+
offsetBeforeMinutes: before / 60,
|
|
492
|
+
offsetAfterMinutes: after / 60,
|
|
493
|
+
cause: Math.abs(after - before) >= 43200 ? "date-line" : place && (at === place.endMs || at === place.legalFrom) ? "legal-change" : recorded >= 0 ? history.causes[recorded] : laterCause(timeZone, at)
|
|
274
494
|
};
|
|
275
|
-
flags.push("dst-gap");
|
|
276
495
|
}
|
|
277
|
-
|
|
496
|
+
const lmt = inEra || !place && history?.zoneEraEnd != null && chosen.utcMs < history.zoneEraEnd;
|
|
497
|
+
const flags = kind ? [kind === "gap" ? "dst-gap" : "dst-fold"] : [];
|
|
498
|
+
if (lmt) flags.push("lmt");
|
|
499
|
+
const localMeanTime = longitude !== void 0 && place && (inEra || kind === "gap" && reading.at === place.endMs) ? { longitude, zoneOffsetMinutes: zoneReading.chosen.offset / 60 } : null;
|
|
500
|
+
const zone = shipped ? {
|
|
501
|
+
source: "tzdb",
|
|
502
|
+
tzdbVersion: TZDB.version,
|
|
503
|
+
dataForm: history.hostLegal ? "main" : "main+backzone",
|
|
504
|
+
abbreviation: inEra ? null : history.abbreviations[type],
|
|
505
|
+
dst: !inEra && history.dst[type]
|
|
506
|
+
} : { source: "intl", tzdbVersion: hostTzdbVersion(), dataForm: "host", abbreviation: null, dst: null };
|
|
507
|
+
const offsetMinutes = chosen.offset / 60;
|
|
278
508
|
return {
|
|
279
|
-
utc: new Date(chosen.
|
|
280
|
-
offsetMinutes
|
|
281
|
-
flags
|
|
509
|
+
utc: new Date(chosen.utcMs),
|
|
510
|
+
offsetMinutes,
|
|
511
|
+
flags,
|
|
512
|
+
date: gregorianDate,
|
|
513
|
+
writtenDate: date,
|
|
514
|
+
calendar,
|
|
515
|
+
jump: kind && transition ? { kind, cause: transition.cause } : null,
|
|
516
|
+
transition,
|
|
517
|
+
localMeanTime,
|
|
518
|
+
zone,
|
|
519
|
+
intlOffsetMinutes: shipped ? offsetAt(timeZone, chosen.utcMs) : null,
|
|
520
|
+
calendarNote: country === void 0 ? null : calendarNote(gregorianDate, calendar, country),
|
|
521
|
+
localResolution: {
|
|
522
|
+
date: gregorianDate,
|
|
523
|
+
time,
|
|
524
|
+
timeZone,
|
|
525
|
+
offsetMinutes,
|
|
526
|
+
gapShiftMinutes: kind === "gap" && transition ? transition.offsetAfterMinutes - transition.offsetBeforeMinutes : 0,
|
|
527
|
+
policy: { fold: "earlier", gap: "shift-forward" },
|
|
528
|
+
calendar,
|
|
529
|
+
writtenDate: date,
|
|
530
|
+
tzdbVersion: zone.tzdbVersion,
|
|
531
|
+
dataForm: zone.dataForm,
|
|
532
|
+
clock: lmt ? "local-mean-time" : "legal",
|
|
533
|
+
transition,
|
|
534
|
+
localMeanTime
|
|
535
|
+
}
|
|
282
536
|
};
|
|
283
537
|
}
|
|
284
|
-
function
|
|
538
|
+
function prepareLocalTime(date, timeZone) {
|
|
539
|
+
try {
|
|
540
|
+
if (typeof date !== "string" || !/^\d{4}-\d{2}-\d{2}$/u.test(date)) throw new RangeError("date must be YYYY-MM-DD.");
|
|
541
|
+
offsetFormatter(timeZone);
|
|
542
|
+
} catch (error) {
|
|
543
|
+
return Promise.reject(error);
|
|
544
|
+
}
|
|
545
|
+
return Number(date.slice(0, 4)) > 1970 || FIXED_ZONE.test(timeZone) ? Promise.resolve() : loadHistory(timeZone);
|
|
546
|
+
}
|
|
547
|
+
function zoneOffsetAt(timeZone, utcMilliseconds) {
|
|
548
|
+
validateInstant(utcMilliseconds);
|
|
549
|
+
offsetFormatter(timeZone);
|
|
550
|
+
const loaded = FIXED_ZONE.test(timeZone) ? null : loadedHistory(timeZone);
|
|
551
|
+
if (loaded === void 0 && utcMilliseconds < 0) throw notLoaded();
|
|
552
|
+
return zoneClock(timeZone, loaded ?? null)(utcMilliseconds) / 60;
|
|
553
|
+
}
|
|
554
|
+
function notLoaded() {
|
|
555
|
+
return new Error("The zone's history before 1970 is not loaded: await prepareLocalTime(date, timeZone) first.");
|
|
556
|
+
}
|
|
557
|
+
var LOCAL_BIRTH_KEYS = [
|
|
558
|
+
"date",
|
|
559
|
+
"time",
|
|
560
|
+
"timeZone",
|
|
561
|
+
"latitude",
|
|
562
|
+
"longitude",
|
|
563
|
+
"houseSystem",
|
|
564
|
+
"timeKnown",
|
|
565
|
+
"calendar",
|
|
566
|
+
"country"
|
|
567
|
+
];
|
|
568
|
+
function resolveLocalBirth(input) {
|
|
285
569
|
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
286
570
|
throw new RangeError("birth must be an object containing a local date and timezone.");
|
|
287
571
|
}
|
|
288
|
-
const
|
|
289
|
-
|
|
572
|
+
for (const key of Object.getOwnPropertyNames(input)) {
|
|
573
|
+
if (!LOCAL_BIRTH_KEYS.includes(key)) throw new RangeError(`Unknown local birth field "${key}".`);
|
|
574
|
+
}
|
|
575
|
+
const fields = Object.fromEntries(LOCAL_BIRTH_KEYS.map((key) => [key, input[key]]));
|
|
576
|
+
const settings = validateBirthSettings(fields);
|
|
577
|
+
const time = fields.time;
|
|
290
578
|
const timeKnown = settings.timeKnown ?? time !== void 0;
|
|
291
579
|
if (timeKnown && time === void 0) {
|
|
292
580
|
throw new RangeError("time is required when timeKnown is true.");
|
|
293
581
|
}
|
|
294
|
-
const resolution = resolveLocalToUtc(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
);
|
|
582
|
+
const resolution = resolveLocalToUtc(fields.date, time === void 0 ? "12:00" : time, fields.timeZone, {
|
|
583
|
+
longitude: settings.longitude,
|
|
584
|
+
calendar: fields.calendar,
|
|
585
|
+
country: fields.country
|
|
586
|
+
});
|
|
299
587
|
return {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
588
|
+
birth: {
|
|
589
|
+
utc: resolution.utc,
|
|
590
|
+
timeKnown,
|
|
591
|
+
houseSystem: settings.houseSystem ?? "whole",
|
|
592
|
+
flags: resolution.flags,
|
|
593
|
+
...settings.latitude === void 0 ? {} : { latitude: settings.latitude, longitude: settings.longitude }
|
|
594
|
+
},
|
|
595
|
+
resolution,
|
|
596
|
+
reference: time === void 0 ? "local-noon" : "supplied-instant"
|
|
305
597
|
};
|
|
306
598
|
}
|
|
599
|
+
function resolveBirth(input) {
|
|
600
|
+
return resolveLocalBirth(input).birth;
|
|
601
|
+
}
|
|
307
602
|
export {
|
|
603
|
+
GREGORIAN_ADOPTION,
|
|
604
|
+
GREGORIAN_ADOPTION_SOURCES,
|
|
605
|
+
TZDB,
|
|
606
|
+
calendarNote,
|
|
308
607
|
createGeoNamesClient,
|
|
608
|
+
gregorianAdoption,
|
|
609
|
+
gregorianToJulian,
|
|
610
|
+
julianToGregorian,
|
|
309
611
|
offsetAt,
|
|
612
|
+
prepareLocalTime,
|
|
310
613
|
resolveBirth,
|
|
311
|
-
|
|
614
|
+
resolveLocalBirth,
|
|
615
|
+
resolveLocalToUtc,
|
|
616
|
+
zoneOffsetAt
|
|
312
617
|
};
|