@zodiacs/engine 0.1.1-rc.15 → 1.0.0

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 (54) hide show
  1. package/CHANGELOG.md +891 -0
  2. package/LICENSING.md +192 -12
  3. package/NOTICE +96 -2
  4. package/README.md +296 -66
  5. package/dist/{api-CoB_kqE3.d.ts → api-WbxJ4Wj-.d.ts} +15 -10
  6. package/dist/ayanamsa--YQ46fET.d.ts +134 -0
  7. package/dist/calc.d.ts +390 -0
  8. package/dist/calc.js +1039 -0
  9. package/dist/chunk-47ERTK5X.js +27 -0
  10. package/dist/chunk-7TRLIFFI.js +56 -0
  11. package/dist/chunk-A3U2ZS2W.js +29 -0
  12. package/dist/{chunk-KHBLFXFG.js → chunk-B5LKF437.js} +29 -28
  13. package/dist/{chunk-ONBZ4HK7.js → chunk-BHJXUY67.js} +4 -2
  14. package/dist/{chunk-OYGRVGXD.js → chunk-CHSYDKBL.js} +3 -3
  15. package/dist/{chunk-ZHVI3KWJ.js → chunk-DMGHYCDI.js} +4 -4
  16. package/dist/{chunk-CWI4YUDL.js → chunk-FTX3JDJA.js} +21 -18
  17. package/dist/{chunk-MFF3VKO3.js → chunk-OG4OYTJJ.js} +47 -42
  18. package/dist/{chunk-ZZPITHQS.js → chunk-SRXBTP5H.js} +199 -65
  19. package/dist/{chunk-AECKV73C.js → chunk-TSS2SZWQ.js} +8 -2
  20. package/dist/chunk-WS3TDSP3.js +474 -0
  21. package/dist/chunk-YIITY7Q7.js +483 -0
  22. package/dist/crossings.d.ts +8 -7
  23. package/dist/crossings.js +1 -1
  24. package/dist/deltat.d.ts +28 -3
  25. package/dist/deltat.js +1 -1
  26. package/dist/geo.d.ts +33 -12
  27. package/dist/geo.js +17 -458
  28. package/dist/{internal-math-BbktkHCc.d.ts → houses-CFERsAlK.d.ts} +14 -160
  29. package/dist/houses-extra.d.ts +95 -0
  30. package/dist/houses-extra.js +339 -0
  31. package/dist/index.d.ts +34 -48
  32. package/dist/index.js +31 -23
  33. package/dist/internal-math-DJJ8BYex.d.ts +174 -0
  34. package/dist/internal-math.d.ts +3 -2
  35. package/dist/internal-math.js +2 -2
  36. package/dist/internal.d.ts +1 -1
  37. package/dist/internal.js +5 -5
  38. package/dist/receipt.d.ts +2 -243
  39. package/dist/receipt.js +78 -37
  40. package/dist/reference-span-CILpclrz.d.ts +40 -0
  41. package/dist/rulers-Dla6h_Sm.d.ts +15 -0
  42. package/dist/sky.d.ts +173 -0
  43. package/dist/sky.js +379 -0
  44. package/dist/techniques.d.ts +453 -0
  45. package/dist/techniques.js +823 -0
  46. package/dist/timing.d.ts +113 -17
  47. package/dist/timing.js +98 -64
  48. package/dist/{types-BsWaqwU_.d.ts → types-B-yb_tGL.d.ts} +23 -11
  49. package/dist/vedic.d.ts +42 -124
  50. package/dist/vedic.js +44 -458
  51. package/dist/window.d.ts +180 -0
  52. package/dist/window.js +960 -0
  53. package/dist/zone-history-ghdyO0Sc.d.ts +268 -0
  54. package/package.json +25 -3
package/dist/geo.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as HouseSystem, d as BirthInput } from './types-BsWaqwU_.js';
2
- import { NatalLocalResolution } from './receipt.js';
1
+ import { H as HouseSystem, h as BirthInput } from './types-B-yb_tGL.js';
2
+ import { T as TransitionCause, N as NatalLocalResolution } from './zone-history-ghdyO0Sc.js';
3
3
  import './deltat.js';
4
4
 
5
5
  interface City {
@@ -71,19 +71,25 @@ interface CalendarNote {
71
71
  kind: "old-style" | "new-style";
72
72
  adoption: Readonly<GregorianAdoption>;
73
73
  }
74
- /** The note for a Gregorian date (as resolved) written in `calendar`, or null. */
74
+ /**
75
+ * The note for a Gregorian date (as resolved, YYYY-MM-DD) written in
76
+ * `calendar`, or null; null too for a country the table does not date. A date
77
+ * that is not a valid Gregorian YYYY-MM-DD, a calendar other than "gregorian"
78
+ * and "julian", or a country that is not a nonempty string throws a
79
+ * RangeError.
80
+ */
75
81
  declare function calendarNote(gregorianDate: string, calendar: CalendarName, country: string): CalendarNote | null;
76
82
 
77
- /** The pinned tzdb release: its version, archive digest and the form its histories were compiled from. */
83
+ /**
84
+ * The pinned tzdb release: its version, archive digest and the form its histories were compiled from. The
85
+ * version and digest are typed as strings, because a release that updates the time-zone data changes them.
86
+ */
78
87
  declare const TZDB: Readonly<{
79
- readonly version: "2025c";
80
- readonly sha256: "4aa79e4effee53fc4029ffe5f6ebe97937282ebcdf386d5d2da91ce84142f957";
81
- readonly form: "main+backzone";
88
+ version: string;
89
+ sha256: string;
90
+ form: "main+backzone";
82
91
  }>;
83
92
 
84
- /** What changed at a transition, from the tzdb record. */
85
- type TransitionCause = "dst" | "legal-change" | "date-line";
86
-
87
93
  /** How to read a wall time (docs/time.md). Unknown keys and values throw RangeError. */
88
94
  interface LocalTimeOptions {
89
95
  /** The birthplace, degrees east: its own mean time replaces the zone's local mean time. */
@@ -150,7 +156,13 @@ interface LocalBirthInput {
150
156
  calendar?: CalendarName;
151
157
  country?: string;
152
158
  }
153
- /** UTC offset for an IANA timezone at a UTC instant, from the host's Intl. */
159
+ /**
160
+ * UTC offset for an IANA timezone at a UTC instant, minutes east, from the
161
+ * host's Intl: a cross-check on the host's time-zone data. zoneOffsetAt is the
162
+ * engine's own answer, the one its wall times use; the two agree from 1970
163
+ * where the host has tzdata 2025c, and before 1970 they can differ, because
164
+ * Intl does not carry the history this package ships.
165
+ */
154
166
  declare function offsetAt(timeZone: string, utcMilliseconds: number): number;
155
167
  /**
156
168
  * Resolve a local wall time in an IANA zone to UTC: a repeated one takes the
@@ -173,6 +185,15 @@ declare function prepareLocalTime(date: string, timeZone: string): Promise<void>
173
185
  * and in the fixed zones, Intl.
174
186
  */
175
187
  declare function zoneOffsetAt(timeZone: string, utcMilliseconds: number): number;
188
+ /**
189
+ * Thrown when an answer needs a zone's history before 1970 and
190
+ * `prepareLocalTime` has not loaded it. An Error, not a RangeError: the input
191
+ * is valid, and awaiting `prepareLocalTime(date, timeZone)` first answers it.
192
+ */
193
+ declare class ZoneHistoryNotLoadedError extends Error {
194
+ readonly name = "ZoneHistoryNotLoadedError";
195
+ constructor();
196
+ }
176
197
  /** A local birth resolved, with how its wall time was read and the receipt's `reference`. */
177
198
  interface LocalBirthResolution {
178
199
  birth: BirthInput;
@@ -184,4 +205,4 @@ declare function resolveLocalBirth(input: LocalBirthInput): LocalBirthResolution
184
205
  /** Convert a local birth form into the explicit UTC input accepted by the core. */
185
206
  declare function resolveBirth(input: LocalBirthInput): BirthInput;
186
207
 
187
- export { type CalendarName, type CalendarNote, type City, GREGORIAN_ADOPTION, GREGORIAN_ADOPTION_SOURCES, type GeoNamesClient, type GeoNamesClientOptions, type GeoNamesIndexMetadata, type GregorianAdoption, type GregorianAdoptionSource, type LocalBirthInput, type LocalBirthResolution, type LocalTimeOptions, type LocalTimeResolution, TZDB, type TransitionCause, type ZoneTransition, calendarNote, createGeoNamesClient, gregorianAdoption, gregorianToJulian, julianToGregorian, offsetAt, prepareLocalTime, resolveBirth, resolveLocalBirth, resolveLocalToUtc, zoneOffsetAt };
208
+ export { type CalendarName, type CalendarNote, type City, GREGORIAN_ADOPTION, GREGORIAN_ADOPTION_SOURCES, type GeoNamesClient, type GeoNamesClientOptions, type GeoNamesIndexMetadata, type GregorianAdoption, type GregorianAdoptionSource, type LocalBirthInput, type LocalBirthResolution, type LocalTimeOptions, type LocalTimeResolution, TZDB, TransitionCause, ZoneHistoryNotLoadedError, type ZoneTransition, calendarNote, createGeoNamesClient, gregorianAdoption, gregorianToJulian, julianToGregorian, offsetAt, prepareLocalTime, resolveBirth, resolveLocalBirth, resolveLocalToUtc, zoneOffsetAt };
package/dist/geo.js CHANGED
@@ -1,14 +1,22 @@
1
1
  import {
2
- civilDateOf,
3
- format,
2
+ GREGORIAN_ADOPTION,
3
+ GREGORIAN_ADOPTION_SOURCES,
4
+ TZDB,
5
+ ZoneHistoryNotLoadedError,
6
+ calendarNote,
7
+ gregorianAdoption,
8
+ offsetAt,
9
+ prepareLocalTime,
10
+ resolveBirth,
11
+ resolveLocalBirth,
12
+ resolveLocalToUtc,
13
+ zoneOffsetAt
14
+ } from "./chunk-YIITY7Q7.js";
15
+ import {
4
16
  gregorianToJulian,
5
- julianDayNumber,
6
- julianToGregorian,
7
- parseCalendarDate
17
+ julianToGregorian
8
18
  } from "./chunk-KFTJMMG7.js";
9
- import {
10
- validateBirthSettings
11
- } from "./chunk-PFGUCNOK.js";
19
+ import "./chunk-PFGUCNOK.js";
12
20
 
13
21
  // src/geo/geonames.ts
14
22
  var fold = (value) => value.normalize("NFD").replace(/[\u0300-\u036f]/gu, "").toLowerCase();
@@ -149,460 +157,11 @@ function createGeoNamesClient(options) {
149
157
  }
150
158
  };
151
159
  }
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
-
329
- // src/geo/timezone.ts
330
- var offsetFormatters = /* @__PURE__ */ new Map();
331
- function validateTimeZone(timeZone) {
332
- if (typeof timeZone !== "string" || timeZone.trim().length === 0) {
333
- throw new RangeError("timeZone must be an explicit nonempty timezone string.");
334
- }
335
- }
336
- function offsetFormatter(timeZone) {
337
- validateTimeZone(timeZone);
338
- let formatter = offsetFormatters.get(timeZone);
339
- if (!formatter) {
340
- formatter = new Intl.DateTimeFormat("en-US", {
341
- timeZone,
342
- calendar: "gregory",
343
- numberingSystem: "latn",
344
- timeZoneName: "longOffset"
345
- });
346
- offsetFormatters.set(timeZone, formatter);
347
- }
348
- return formatter;
349
- }
350
- function validateInstant(utcMilliseconds) {
351
- if (typeof utcMilliseconds !== "number" || !Number.isFinite(utcMilliseconds)) {
352
- throw new RangeError("utcMilliseconds must be a finite epoch-millisecond timestamp.");
353
- }
354
- }
355
- function offsetAt(timeZone, utcMilliseconds) {
356
- validateInstant(utcMilliseconds);
357
- const name = offsetFormatter(timeZone).formatToParts(utcMilliseconds).find((part) => part.type === "timeZoneName")?.value;
358
- const match = (name ?? "GMT").match(/^GMT(?:([+-])(\d{1,2})(?::(\d{2}))?(?::(\d{2}))?)?$/u);
359
- if (!match) {
360
- throw new RangeError(`Could not read UTC offset for timezone: ${timeZone}`);
361
- }
362
- const sign = match[1] === "-" ? -1 : 1;
363
- return sign * (Number(match[2] ?? 0) * 60 + Number(match[3] ?? 0) + Number(match[4] ?? 0) / 60);
364
- }
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;
379
- }
380
- return hi;
381
- }
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
- }
389
- }
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 };
393
- }
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;
400
- }
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.");
433
- }
434
- for (const key of Object.getOwnPropertyNames(options)) {
435
- if (!["longitude", "calendar", "country"].includes(key)) throw new RangeError(`Unknown local time option "${key}".`);
436
- }
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)
494
- };
495
- }
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;
508
- return {
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
- }
536
- };
537
- }
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) {
569
- if (!input || typeof input !== "object" || Array.isArray(input)) {
570
- throw new RangeError("birth must be an object containing a local date and timezone.");
571
- }
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;
578
- const timeKnown = settings.timeKnown ?? time !== void 0;
579
- if (timeKnown && time === void 0) {
580
- throw new RangeError("time is required when timeKnown is true.");
581
- }
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
- });
587
- return {
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"
597
- };
598
- }
599
- function resolveBirth(input) {
600
- return resolveLocalBirth(input).birth;
601
- }
602
160
  export {
603
161
  GREGORIAN_ADOPTION,
604
162
  GREGORIAN_ADOPTION_SOURCES,
605
163
  TZDB,
164
+ ZoneHistoryNotLoadedError,
606
165
  calendarNote,
607
166
  createGeoNamesClient,
608
167
  gregorianAdoption,