@nextera.one/tps-standard 0.5.1 → 0.5.3

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 (39) hide show
  1. package/README.md +91 -467
  2. package/dist/drivers/gregorian.d.ts +18 -0
  3. package/dist/drivers/gregorian.js +157 -0
  4. package/dist/drivers/gregorian.js.map +1 -0
  5. package/dist/drivers/hijri.d.ts +42 -0
  6. package/dist/drivers/hijri.js +281 -0
  7. package/dist/drivers/hijri.js.map +1 -0
  8. package/dist/drivers/holocene.d.ts +25 -0
  9. package/dist/drivers/holocene.js +132 -0
  10. package/dist/drivers/holocene.js.map +1 -0
  11. package/dist/drivers/julian.d.ts +33 -0
  12. package/dist/drivers/julian.js +225 -0
  13. package/dist/drivers/julian.js.map +1 -0
  14. package/dist/drivers/persian.d.ts +33 -0
  15. package/dist/drivers/persian.js +269 -0
  16. package/dist/drivers/persian.js.map +1 -0
  17. package/dist/drivers/tps.d.ts +55 -0
  18. package/dist/drivers/tps.js +235 -0
  19. package/dist/drivers/tps.js.map +1 -0
  20. package/dist/drivers/unix.d.ts +16 -0
  21. package/dist/drivers/unix.js +76 -0
  22. package/dist/drivers/unix.js.map +1 -0
  23. package/dist/index.d.ts +174 -41
  24. package/dist/index.js +803 -321
  25. package/dist/index.js.map +1 -0
  26. package/package.json +9 -3
  27. package/src/drivers/gregorian.ts +191 -0
  28. package/src/drivers/hijri.ts +322 -0
  29. package/src/drivers/holocene.ts +152 -0
  30. package/src/drivers/julian.ts +255 -0
  31. package/src/drivers/persian.ts +298 -0
  32. package/src/drivers/tps.ts +270 -0
  33. package/src/drivers/unix.ts +79 -0
  34. package/src/index.ts +959 -366
  35. package/dist/src/index.js +0 -681
  36. package/dist/test/src/index.js +0 -963
  37. package/dist/test/test/persian-calendar.test.js +0 -488
  38. package/dist/test/test/tps-uid.test.js +0 -295
  39. package/dist/test/tps-uid.test.js +0 -240
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GregorianDriver = void 0;
4
+ const index_1 = require("../index");
5
+ /**
6
+ * Gregorian calendar driver.
7
+ * This mirrors the built-in logic that used to live in `TPS.fromDate`/`toDate`
8
+ * and provides implementations for the full `CalendarDriver` interface.
9
+ * The driver also implements the optional helpers, enabling unit tests to
10
+ * exercise `parseDate`, `format`, `validate`, and `getMetadata`.
11
+ */
12
+ class GregorianDriver {
13
+ constructor() {
14
+ this.code = "greg";
15
+ }
16
+ getComponentsFromDate(date) {
17
+ const fullYear = date.getUTCFullYear();
18
+ return {
19
+ calendar: this.code,
20
+ millennium: Math.floor(fullYear / 1000) + 1,
21
+ century: Math.floor((fullYear % 1000) / 100) + 1,
22
+ year: fullYear % 100,
23
+ month: date.getUTCMonth() + 1,
24
+ day: date.getUTCDate(),
25
+ hour: date.getUTCHours(),
26
+ minute: date.getUTCMinutes(),
27
+ second: date.getUTCSeconds(),
28
+ millisecond: date.getUTCMilliseconds(),
29
+ };
30
+ }
31
+ getDateFromComponents(components) {
32
+ const m = components.millennium ?? 0;
33
+ const c = components.century ?? 1;
34
+ const y = components.year ?? 0;
35
+ const fullYear = (m - 1) * 1000 + (c - 1) * 100 + y;
36
+ return new Date(Date.UTC(fullYear, (components.month || 1) - 1, components.day || 1, components.hour || 0, components.minute || 0, Math.floor(components.second || 0), components.millisecond ??
37
+ Math.round(((components.second || 0) % 1) * 1000)));
38
+ }
39
+ getFromDate(date) {
40
+ const comp = this.getComponentsFromDate(date);
41
+ // buildTimePart understands the `order` field if the caller has set it
42
+ return index_1.TPS.buildTimePart(comp);
43
+ }
44
+ // --- optional helpers --------------------------------------------------
45
+ parseDate(input, format) {
46
+ // Accept ISO-like formats: "YYYY-MM-DD" and optionally time portion
47
+ const s = input.trim();
48
+ // simple regex - not exhaustive
49
+ const m = s.match(/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?$/);
50
+ if (!m) {
51
+ throw new Error(`GregorianDriver.parseDate: unsupported format "${input}"`);
52
+ }
53
+ const year = parseInt(m[1], 10);
54
+ const month = parseInt(m[2], 10);
55
+ const day = parseInt(m[3], 10);
56
+ const hour = m[4] !== undefined ? parseInt(m[4], 10) : undefined;
57
+ const minute = m[5] !== undefined ? parseInt(m[5], 10) : undefined;
58
+ const second = m[6] !== undefined ? parseInt(m[6], 10) : undefined;
59
+ const millisecond = m[7] !== undefined ? parseInt((m[7] + "000").slice(0, 3), 10) : undefined;
60
+ const comp = {
61
+ calendar: this.code,
62
+ year,
63
+ month,
64
+ day,
65
+ };
66
+ if (hour !== undefined)
67
+ comp.hour = hour;
68
+ if (minute !== undefined)
69
+ comp.minute = minute;
70
+ if (second !== undefined)
71
+ comp.second = second;
72
+ if (millisecond !== undefined)
73
+ comp.millisecond = millisecond;
74
+ return comp;
75
+ }
76
+ format(components, format) {
77
+ // For simplicity we ignore `format` and always produce ISO-ish string
78
+ const y = components.year !== undefined
79
+ ? String(components.year).padStart(4, "0")
80
+ : "0000";
81
+ const mo = components.month !== undefined
82
+ ? String(components.month).padStart(2, "0")
83
+ : "01";
84
+ const d = components.day !== undefined
85
+ ? String(components.day).padStart(2, "0")
86
+ : "01";
87
+ let out = `${y}-${mo}-${d}`;
88
+ if (components.hour !== undefined ||
89
+ components.minute !== undefined ||
90
+ components.second !== undefined ||
91
+ components.millisecond !== undefined) {
92
+ const h = components.hour !== undefined
93
+ ? String(components.hour).padStart(2, "0")
94
+ : "00";
95
+ const mi = components.minute !== undefined
96
+ ? String(components.minute).padStart(2, "0")
97
+ : "00";
98
+ const s = components.second !== undefined
99
+ ? String(Math.floor(components.second)).padStart(2, "0")
100
+ : "00";
101
+ const ms = components.millisecond !== undefined
102
+ ? String(components.millisecond).padStart(3, "0")
103
+ : "000";
104
+ out += `T${h}:${mi}:${s}.${ms}`;
105
+ }
106
+ return out;
107
+ }
108
+ validate(input) {
109
+ if (typeof input === "string") {
110
+ // basic ISO date with optional time and fractional seconds
111
+ return /^\d{4}-\d{2}-\d{2}(?:[ T]\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?)?$/.test(input.trim());
112
+ }
113
+ if (typeof input === "object") {
114
+ return (input.year !== undefined &&
115
+ input.month !== undefined &&
116
+ input.day !== undefined &&
117
+ input.year >= 0 &&
118
+ input.month >= 1 &&
119
+ input.month <= 12 &&
120
+ input.day >= 1 &&
121
+ input.day <= 31);
122
+ }
123
+ return false;
124
+ }
125
+ getMetadata() {
126
+ return {
127
+ name: "Gregorian",
128
+ monthNames: [
129
+ "January",
130
+ "February",
131
+ "March",
132
+ "April",
133
+ "May",
134
+ "June",
135
+ "July",
136
+ "August",
137
+ "September",
138
+ "October",
139
+ "November",
140
+ "December",
141
+ ],
142
+ dayNames: [
143
+ "Sunday",
144
+ "Monday",
145
+ "Tuesday",
146
+ "Wednesday",
147
+ "Thursday",
148
+ "Friday",
149
+ "Saturday",
150
+ ],
151
+ monthsPerYear: 12,
152
+ epochYear: 1,
153
+ };
154
+ }
155
+ }
156
+ exports.GregorianDriver = GregorianDriver;
157
+ //# sourceMappingURL=gregorian.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gregorian.js","sourceRoot":"","sources":["../../src/drivers/gregorian.ts"],"names":[],"mappings":";;;AAAA,oCAMkB;AAElB;;;;;;GAMG;AACH,MAAa,eAAe;IAA5B;QACW,SAAI,GAAW,MAAM,CAAC;IA8KjC,CAAC;IA5KC,qBAAqB,CAAC,IAAU;QAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QACvC,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,IAAI;YACnB,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC;YAC3C,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC;YAChD,IAAI,EAAE,QAAQ,GA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K,QAAQ,EAAE,CAAC;YAC9B,OAAO,CACL,KAAK,CAAC,IAAI,KAAK,SAAS;gBACxB,KAAK,CAAC,KAAK,KAAK,SAAS;gBACzB,KAAK,CAAC,GAAG,KAAK,SAAS;gBACvB,KAAK,CAAC,IAAI,IAAI,CAAC;gBACf,KAAK,CAAC,KAAK,IAAI,CAAC;gBAChB,KAAK,CAAC,KAAK,IAAI,EAAE;gBACjB,KAAK,CAAC,GAAG,IAAI,CAAC;gBACd,KAAK,CAAC,GAAG,IAAI,EAAE,CAChB,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW;QACT,OAAO;YACL,IAAI,EAAE,WAAW;YACjB,UAAU,EAAE;gBACV,SAAS;gBACT,UAAU;gBACV,OAAO;gBACP,OAAO;gBACP,KAAK;gBACL,MAAM;gBACN,MAAM;gBACN,QAAQ;gBACR,WAAW;gBACX,SAAS;gBACT,UAAU;gBACV,UAAU;aACX;YACD,QAAQ,EAAE;gBACR,QAAQ;gBACR,QAAQ;gBACR,SAAS;gBACT,WAAW;gBACX,UAAU;gBACV,QAAQ;gBACR,UAAU;aACX;YACD,aAAa,EAAE,EAAE;YACjB,SAAS,EAAE,CAAC;SACb,CAAC;IACJ,CAAC;CACF;AA/KD,0CA+KC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Hijri (Islamic) Calendar Driver — Tabular / Arithmetic variant
3
+ *
4
+ * Calendar characteristics:
5
+ * - Lunar calendar with 12 months of alternating 30/29 days
6
+ * - 30-year cycle with 11 leap years (Dhul Hijjah gains a day)
7
+ * - Year 1 AH ≈ 16 July 622 CE (Julian)
8
+ * - Average year ≈ 354.36667 days
9
+ *
10
+ * This uses the Tabular Islamic Calendar (civil/Type II-A) algorithm
11
+ * based on the formulas from Meeus "Astronomical Algorithms".
12
+ */
13
+ import { CalendarDriver, CalendarMetadata, TPSComponents } from "../index";
14
+ export declare class HijriDriver implements CalendarDriver {
15
+ readonly code = "hij";
16
+ readonly name = "Hijri (Islamic Calendar)";
17
+ private readonly MONTH_NAMES;
18
+ private readonly MONTH_NAMES_SHORT;
19
+ private readonly DAY_NAMES;
20
+ /** Leap years in a 30-year cycle (civil / Type II-A pattern) */
21
+ private readonly LEAP_YEARS_IN_CYCLE;
22
+ getComponentsFromDate(date: Date): Partial<TPSComponents>;
23
+ getDateFromComponents(components: Partial<TPSComponents>): Date;
24
+ getFromDate(date: Date): string;
25
+ parseDate(input: string, format?: string): Partial<TPSComponents>;
26
+ format(components: Partial<TPSComponents>, format?: string): string;
27
+ validate(input: string | Partial<TPSComponents>): boolean;
28
+ getMetadata(): CalendarMetadata;
29
+ private isLeapYear;
30
+ private daysInMonth;
31
+ /**
32
+ * Convert Gregorian to Hijri (Tabular Islamic Calendar).
33
+ * Algorithm from "Astronomical Algorithms" by Jean Meeus.
34
+ */
35
+ private gregorianToHijri;
36
+ /**
37
+ * Convert Hijri to Gregorian.
38
+ */
39
+ private hijriToGregorian;
40
+ private gregorianToJdn;
41
+ private jdnToGregorian;
42
+ }
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HijriDriver = void 0;
4
+ /**
5
+ * Hijri (Islamic) Calendar Driver — Tabular / Arithmetic variant
6
+ *
7
+ * Calendar characteristics:
8
+ * - Lunar calendar with 12 months of alternating 30/29 days
9
+ * - 30-year cycle with 11 leap years (Dhul Hijjah gains a day)
10
+ * - Year 1 AH ≈ 16 July 622 CE (Julian)
11
+ * - Average year ≈ 354.36667 days
12
+ *
13
+ * This uses the Tabular Islamic Calendar (civil/Type II-A) algorithm
14
+ * based on the formulas from Meeus "Astronomical Algorithms".
15
+ */
16
+ const index_1 = require("../index");
17
+ class HijriDriver {
18
+ constructor() {
19
+ this.code = "hij";
20
+ this.name = "Hijri (Islamic Calendar)";
21
+ this.MONTH_NAMES = [
22
+ "Muharram",
23
+ "Safar",
24
+ "Rabi' al-Awwal",
25
+ "Rabi' al-Thani",
26
+ "Jumada al-Ula",
27
+ "Jumada al-Thani",
28
+ "Rajab",
29
+ "Sha'ban",
30
+ "Ramadan",
31
+ "Shawwal",
32
+ "Dhu al-Qi'dah",
33
+ "Dhu al-Hijjah",
34
+ ];
35
+ this.MONTH_NAMES_SHORT = [
36
+ "Muh",
37
+ "Saf",
38
+ "Rab I",
39
+ "Rab II",
40
+ "Jum I",
41
+ "Jum II",
42
+ "Raj",
43
+ "Sha",
44
+ "Ram",
45
+ "Shaw",
46
+ "Dhu Q",
47
+ "Dhu H",
48
+ ];
49
+ this.DAY_NAMES = [
50
+ "al-Ahad",
51
+ "al-Ithnayn",
52
+ "ath-Thulatha",
53
+ "al-Arbi'a",
54
+ "al-Khamis",
55
+ "al-Jumu'ah",
56
+ "as-Sabt",
57
+ ];
58
+ /** Leap years in a 30-year cycle (civil / Type II-A pattern) */
59
+ this.LEAP_YEARS_IN_CYCLE = new Set([
60
+ 2, 5, 7, 10, 13, 16, 18, 21, 24, 26, 29,
61
+ ]);
62
+ }
63
+ // ── CalendarDriver interface ──────────────────────────────────────────
64
+ getComponentsFromDate(date) {
65
+ const { hy, hm, hd } = this.gregorianToHijri(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate());
66
+ return {
67
+ calendar: this.code,
68
+ millennium: Math.floor(hy / 1000) + 1,
69
+ century: Math.floor((hy % 1000) / 100) + 1,
70
+ year: hy % 100,
71
+ month: hm,
72
+ day: hd,
73
+ hour: date.getUTCHours(),
74
+ minute: date.getUTCMinutes(),
75
+ second: date.getUTCSeconds(),
76
+ millisecond: date.getUTCMilliseconds(),
77
+ };
78
+ }
79
+ getDateFromComponents(components) {
80
+ let hy;
81
+ if (components.millennium !== undefined) {
82
+ const m = components.millennium ?? 0;
83
+ const c = components.century ?? 1;
84
+ const y = components.year ?? 0;
85
+ hy = (m - 1) * 1000 + (c - 1) * 100 + y;
86
+ }
87
+ else {
88
+ hy = components.year ?? 1;
89
+ }
90
+ const hm = components.month ?? 1;
91
+ const hd = components.day ?? 1;
92
+ const { gy, gm, gd } = this.hijriToGregorian(hy, hm, hd);
93
+ return new Date(Date.UTC(gy, gm - 1, gd, components.hour ?? 0, components.minute ?? 0, Math.floor(components.second ?? 0), components.millisecond ?? 0));
94
+ }
95
+ getFromDate(date) {
96
+ const comp = this.getComponentsFromDate(date);
97
+ return index_1.TPS.buildTimePart(comp);
98
+ }
99
+ parseDate(input, format) {
100
+ const trimmed = input.trim();
101
+ if (format === "short" ||
102
+ (trimmed.includes("/") && trimmed.split("/")[0].length <= 2)) {
103
+ const [day, month, year] = trimmed.split("/").map(Number);
104
+ return {
105
+ calendar: this.code,
106
+ millennium: Math.floor(year / 1000) + 1,
107
+ century: Math.floor((year % 1000) / 100) + 1,
108
+ year: year % 100,
109
+ month,
110
+ day,
111
+ };
112
+ }
113
+ const segments = trimmed.split(/[\s,T]+/);
114
+ const [fullYear, month, day] = segments[0].split("-").map(Number);
115
+ const result = {
116
+ calendar: this.code,
117
+ millennium: Math.floor(fullYear / 1000) + 1,
118
+ century: Math.floor((fullYear % 1000) / 100) + 1,
119
+ year: fullYear % 100,
120
+ month,
121
+ day,
122
+ };
123
+ if (segments[1]) {
124
+ const [h, m, s] = segments[1].split(":").map(Number);
125
+ result.hour = h ?? 0;
126
+ result.minute = m ?? 0;
127
+ result.second = s ?? 0;
128
+ }
129
+ return result;
130
+ }
131
+ format(components, format) {
132
+ const pad = (n) => String(n ?? 0).padStart(2, "0");
133
+ let fullYear;
134
+ if (components.millennium !== undefined) {
135
+ const m = components.millennium ?? 0;
136
+ const c = components.century ?? 1;
137
+ const y = components.year ?? 0;
138
+ fullYear = (m - 1) * 1000 + (c - 1) * 100 + y;
139
+ }
140
+ else {
141
+ fullYear = components.year ?? 0;
142
+ }
143
+ if (format === "short") {
144
+ return `${components.day}/${pad(components.month)}/${fullYear}`;
145
+ }
146
+ if (format === "long") {
147
+ const mn = this.MONTH_NAMES[(components.month ?? 1) - 1];
148
+ return `${components.day} ${mn} ${fullYear}`;
149
+ }
150
+ let out = `${fullYear}-${pad(components.month)}-${pad(components.day)}`;
151
+ if (components.hour !== undefined) {
152
+ out += ` ${pad(components.hour)}:${pad(components.minute)}:${pad(Math.floor(components.second ?? 0))}`;
153
+ }
154
+ return out;
155
+ }
156
+ validate(input) {
157
+ let comp;
158
+ if (typeof input === "string") {
159
+ try {
160
+ comp = this.parseDate(input);
161
+ }
162
+ catch {
163
+ return false;
164
+ }
165
+ }
166
+ else {
167
+ comp = input;
168
+ }
169
+ const { year, month, day } = comp;
170
+ // Reconstruct full year for leap check
171
+ let fullYear;
172
+ if (comp.millennium !== undefined) {
173
+ fullYear =
174
+ ((comp.millennium ?? 0) - 1) * 1000 +
175
+ ((comp.century ?? 1) - 1) * 100 +
176
+ (year ?? 0);
177
+ }
178
+ else {
179
+ fullYear = year ?? 0;
180
+ }
181
+ if (fullYear < 1)
182
+ return false;
183
+ if (!month || month < 1 || month > 12)
184
+ return false;
185
+ if (!day || day < 1)
186
+ return false;
187
+ const maxDays = this.daysInMonth(fullYear, month);
188
+ return day <= maxDays;
189
+ }
190
+ getMetadata() {
191
+ return {
192
+ name: "Hijri (Islamic Calendar)",
193
+ monthNames: this.MONTH_NAMES,
194
+ monthNamesShort: this.MONTH_NAMES_SHORT,
195
+ dayNames: this.DAY_NAMES,
196
+ dayNamesShort: this.DAY_NAMES.map((d) => d.slice(0, 3)),
197
+ isLunar: true,
198
+ monthsPerYear: 12,
199
+ epochYear: 1,
200
+ };
201
+ }
202
+ // ── Internal helpers ──────────────────────────────────────────────────
203
+ isLeapYear(year) {
204
+ return this.LEAP_YEARS_IN_CYCLE.has(((year - 1) % 30) + 1);
205
+ }
206
+ daysInMonth(year, month) {
207
+ if (month === 12 && this.isLeapYear(year))
208
+ return 30;
209
+ return month % 2 === 1 ? 30 : 29;
210
+ }
211
+ // ── Gregorian ↔ Hijri (Tabular algorithm from Meeus) ──────────────────
212
+ /**
213
+ * Convert Gregorian to Hijri (Tabular Islamic Calendar).
214
+ * Algorithm from "Astronomical Algorithms" by Jean Meeus.
215
+ */
216
+ gregorianToHijri(gy, gm, gd) {
217
+ // Step 1: Gregorian → JDN
218
+ const jdn = this.gregorianToJdn(gy, gm, gd);
219
+ // Step 2: JDN → Hijri
220
+ // L = JDN − 1948440 + 10632
221
+ const L = jdn - 1948440 + 10632;
222
+ // N = floor((L − 1) / 10631)
223
+ const N = Math.floor((L - 1) / 10631);
224
+ // L = L − 10631 × N + 354
225
+ const L2 = L - 10631 * N + 354;
226
+ // J = floor((10985 − L2) / 5316) × floor((50×L2) / 17719) + floor(L2 / 5670) × floor((43×L2) / 15238)
227
+ const J = Math.floor((10985 - L2) / 5316) * Math.floor((50 * L2) / 17719) +
228
+ Math.floor(L2 / 5670) * Math.floor((43 * L2) / 15238);
229
+ // L3 = L2 − floor((30 − J) / 15) × floor((17719 × J) / 50) − floor(J / 16) × floor((15238 × J) / 43) + 29
230
+ const L3 = L2 -
231
+ Math.floor((30 - J) / 15) * Math.floor((17719 * J) / 50) -
232
+ Math.floor(J / 16) * Math.floor((15238 * J) / 43) +
233
+ 29;
234
+ const hm = Math.floor((24 * L3) / 709);
235
+ const hd = L3 - Math.floor((709 * hm) / 24);
236
+ const hy = 30 * N + J - 30;
237
+ return { hy, hm, hd };
238
+ }
239
+ /**
240
+ * Convert Hijri to Gregorian.
241
+ */
242
+ hijriToGregorian(hy, hm, hd) {
243
+ // Hijri → JDN
244
+ const jdn = Math.floor((11 * hy + 3) / 30) +
245
+ 354 * hy +
246
+ 30 * hm -
247
+ Math.floor((hm - 1) / 2) +
248
+ hd +
249
+ 1948440 -
250
+ 385;
251
+ // JDN → Gregorian
252
+ return this.jdnToGregorian(jdn);
253
+ }
254
+ // ── JDN helpers ───────────────────────────────────────────────────────
255
+ gregorianToJdn(gy, gm, gd) {
256
+ const a = Math.floor((14 - gm) / 12);
257
+ const y = gy + 4800 - a;
258
+ const m = gm + 12 * a - 3;
259
+ return (gd +
260
+ Math.floor((153 * m + 2) / 5) +
261
+ 365 * y +
262
+ Math.floor(y / 4) -
263
+ Math.floor(y / 100) +
264
+ Math.floor(y / 400) -
265
+ 32045);
266
+ }
267
+ jdnToGregorian(jdn) {
268
+ const a = jdn + 32044;
269
+ const b = Math.floor((4 * a + 3) / 146097);
270
+ const c = a - Math.floor((146097 * b) / 4);
271
+ const d = Math.floor((4 * c + 3) / 1461);
272
+ const e = c - Math.floor((1461 * d) / 4);
273
+ const m = Math.floor((5 * e + 2) / 153);
274
+ const gd = e - Math.floor((153 * m + 2) / 5) + 1;
275
+ const gm = m + 3 - 12 * Math.floor(m / 10);
276
+ const gy = 100 * b + d - 4800 + Math.floor(m / 10);
277
+ return { gy, gm, gd };
278
+ }
279
+ }
280
+ exports.HijriDriver = HijriDriver;
281
+ //# sourceMappingURL=hijri.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hijri.js","sourceRoot":"","sources":["../../src/drivers/hijri.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,oCAAgF;AAEhF,MAAa,WAAW;IAAxB;QACW,SAAI,GAAG,KAAK,CAAC;QACb,SAAI,GAAG,0BAA0B,CAAC;QAE1B,gBAAW,GAAG;YAC7B,UAAU;YACV,OAAO;YACP,gBAAgB;YAChB,gBAAgB;YAChB,eAAe;YACf,iBAAiB;YACjB,OAAO;YACP,SAAS;YACT,SAAS;YACT,SAAS;YACT,eAAe;YACf,eAAe;SAChB,CAAC;QAEe,sBAAiB,GAAG;YACnC,KAAK;YACL,KAAK;YACL,OAAO;YACP,QAAQ;YACR,OAAO;YACP,QAAQ;YACR,KAAK;YACL,KAAK;YACL,KAAK;YACL,MAAM;YACN,OAAO;YACP,OAAO;SACR,CAAC;QAEe,cAAS,GAAG;YAC3B,SAAS;YACT,YAAY;YACZ,cAAc;YACd,WAAW;YACX,WAAW;YACX,YAAY;YACZ,SAAS;SACV,CAAC;QAEF,gEAAgE;QAC/C,wBAAmB,GAAG,IAAI,GAAG,CAAC;YAC7C,CAAC,EAAE,CAAC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M,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QAC3C,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACzC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACzC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QACxC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACjD,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QAC3C,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACnD,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;IACxB,CAAC;CACF;AAnTD,kCAmTC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Holocene (Human Era) Calendar Driver
3
+ *
4
+ * Calendar characteristics:
5
+ * - Adds 10,000 to the Gregorian year (year 1 CE = 10,001 HE)
6
+ * - Same months, days, and leap year rules as Gregorian
7
+ * - Proposed by Cesare Emiliani in 1993 to encompass all of human history
8
+ * - Also called Human Era (HE) calendar
9
+ *
10
+ * This is a thin wrapper around GregorianDriver with a year offset.
11
+ */
12
+ import { CalendarDriver, CalendarMetadata, TPSComponents } from "../index";
13
+ export declare class HoloceneDriver implements CalendarDriver {
14
+ readonly code = "holo";
15
+ readonly name = "Holocene (Human Era)";
16
+ private readonly gregorian;
17
+ private readonly YEAR_OFFSET;
18
+ getComponentsFromDate(date: Date): Partial<TPSComponents>;
19
+ getDateFromComponents(components: Partial<TPSComponents>): Date;
20
+ getFromDate(date: Date): string;
21
+ parseDate(input: string, format?: string): Partial<TPSComponents>;
22
+ format(components: Partial<TPSComponents>, format?: string): string;
23
+ validate(input: string | Partial<TPSComponents>): boolean;
24
+ getMetadata(): CalendarMetadata;
25
+ }
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HoloceneDriver = void 0;
4
+ /**
5
+ * Holocene (Human Era) Calendar Driver
6
+ *
7
+ * Calendar characteristics:
8
+ * - Adds 10,000 to the Gregorian year (year 1 CE = 10,001 HE)
9
+ * - Same months, days, and leap year rules as Gregorian
10
+ * - Proposed by Cesare Emiliani in 1993 to encompass all of human history
11
+ * - Also called Human Era (HE) calendar
12
+ *
13
+ * This is a thin wrapper around GregorianDriver with a year offset.
14
+ */
15
+ const index_1 = require("../index");
16
+ const gregorian_1 = require("./gregorian");
17
+ class HoloceneDriver {
18
+ constructor() {
19
+ this.code = "holo";
20
+ this.name = "Holocene (Human Era)";
21
+ this.gregorian = new gregorian_1.GregorianDriver();
22
+ this.YEAR_OFFSET = 10000;
23
+ }
24
+ // ── CalendarDriver interface ──────────────────────────────────────────
25
+ getComponentsFromDate(date) {
26
+ const greg = this.gregorian.getComponentsFromDate(date);
27
+ const fullYear = date.getUTCFullYear() + this.YEAR_OFFSET;
28
+ return {
29
+ ...greg,
30
+ calendar: this.code,
31
+ millennium: Math.floor(fullYear / 1000) + 1,
32
+ century: Math.floor((fullYear % 1000) / 100) + 1,
33
+ year: fullYear % 100,
34
+ };
35
+ }
36
+ getDateFromComponents(components) {
37
+ const m = components.millennium ?? 0;
38
+ const c = components.century ?? 1;
39
+ const y = components.year ?? 0;
40
+ const holoYear = (m - 1) * 1000 + (c - 1) * 100 + y;
41
+ const gregYear = holoYear - this.YEAR_OFFSET;
42
+ return new Date(Date.UTC(gregYear, (components.month ?? 1) - 1, components.day ?? 1, components.hour ?? 0, components.minute ?? 0, Math.floor(components.second ?? 0), components.millisecond ??
43
+ Math.round(((components.second ?? 0) % 1) * 1000)));
44
+ }
45
+ getFromDate(date) {
46
+ const comp = this.getComponentsFromDate(date);
47
+ return index_1.TPS.buildTimePart(comp);
48
+ }
49
+ parseDate(input, format) {
50
+ // Accept ISO-like: "12026-01-09" (Holocene year)
51
+ const m = input
52
+ .trim()
53
+ .match(/^(\d{4,5})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?$/);
54
+ if (!m) {
55
+ throw new Error(`HoloceneDriver.parseDate: unsupported format "${input}"`);
56
+ }
57
+ const result = {
58
+ calendar: this.code,
59
+ year: parseInt(m[1], 10),
60
+ month: parseInt(m[2], 10),
61
+ day: parseInt(m[3], 10),
62
+ };
63
+ if (m[4] !== undefined)
64
+ result.hour = parseInt(m[4], 10);
65
+ if (m[5] !== undefined)
66
+ result.minute = parseInt(m[5], 10);
67
+ if (m[6] !== undefined)
68
+ result.second = parseInt(m[6], 10);
69
+ if (m[7] !== undefined)
70
+ result.millisecond = parseInt((m[7] + "000").slice(0, 3), 10);
71
+ return result;
72
+ }
73
+ format(components, format) {
74
+ const pad = (n, w = 2) => String(n ?? 0).padStart(w, "0");
75
+ // Reconstruct full Holocene year from components
76
+ let holoYear;
77
+ if (components.millennium !== undefined) {
78
+ const m = components.millennium ?? 0;
79
+ const c = components.century ?? 1;
80
+ const y = components.year ?? 0;
81
+ holoYear = (m - 1) * 1000 + (c - 1) * 100 + y;
82
+ }
83
+ else {
84
+ holoYear = components.year ?? 0;
85
+ }
86
+ let out = `${String(holoYear).padStart(5, "0")}-${pad(components.month)}-${pad(components.day)}`;
87
+ if (components.hour !== undefined ||
88
+ components.minute !== undefined ||
89
+ components.second !== undefined) {
90
+ out += `T${pad(components.hour)}:${pad(components.minute)}:${pad(Math.floor(components.second ?? 0))}`;
91
+ }
92
+ return out;
93
+ }
94
+ validate(input) {
95
+ if (typeof input === "string") {
96
+ return /^\d{4,5}-\d{2}-\d{2}(?:[ T]\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?)?$/.test(input.trim());
97
+ }
98
+ if (typeof input === "object") {
99
+ // Delegate day/month validation to Gregorian (same structure)
100
+ return this.gregorian.validate({
101
+ year: input.year,
102
+ month: input.month,
103
+ day: input.day,
104
+ });
105
+ }
106
+ return false;
107
+ }
108
+ getMetadata() {
109
+ return {
110
+ name: "Holocene (Human Era)",
111
+ monthNames: [
112
+ "January",
113
+ "February",
114
+ "March",
115
+ "April",
116
+ "May",
117
+ "June",
118
+ "July",
119
+ "August",
120
+ "September",
121
+ "October",
122
+ "November",
123
+ "December",
124
+ ],
125
+ isLunar: false,
126
+ monthsPerYear: 12,
127
+ epochYear: -10000, // 10001 BCE
128
+ };
129
+ }
130
+ }
131
+ exports.HoloceneDriver = HoloceneDriver;
132
+ //# sourceMappingURL=holocene.js.map