@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,235 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TpsDriver = void 0;
4
+ /**
5
+ * TPS calendar driver for canonical TPS time strings.
6
+ *
7
+ * TPS Calendar characteristics:
8
+ * - Epoch: August 11, 1999 (00:00 UTC)
9
+ * - Months: Always 28 days (12 months per year = 336 days)
10
+ * - Time offset: 7 hours ahead of Gregorian (00:00 Gregorian = 07:00 TPS)
11
+ *
12
+ * Conversion process:
13
+ * 1. Apply 7-hour offset to Gregorian date
14
+ * 2. Calculate day-of-year in offset date
15
+ * 3. Convert day-of-year to TPS month/day (each month = 28 days)
16
+ * 4. Preserve millennium/century/year structure
17
+ */
18
+ const index_1 = require("../index");
19
+ const gregorian_1 = require("./gregorian");
20
+ class TpsDriver {
21
+ constructor() {
22
+ this.code = "tps";
23
+ this.name = "TPS Canonical";
24
+ // TPS Epoch: August 11, 1999, 00:00 UTC
25
+ this.TPS_EPOCH = new Date(Date.UTC(1999, 7, 11, 0, 0, 0, 0));
26
+ // TPS is 7 hours ahead of Gregorian
27
+ this.TPS_OFFSET_HOURS = 7;
28
+ // Each TPS month has 28 days
29
+ this.TPS_DAYS_PER_MONTH = 28;
30
+ // TPS has 12 months per year (12 * 28 = 336 days)
31
+ this.TPS_MONTHS_PER_YEAR = 12;
32
+ this.gregorian = new gregorian_1.GregorianDriver();
33
+ }
34
+ /**
35
+ * Converts a Gregorian Date to TPS components.
36
+ * Applies 7-hour offset and converts day-of-year to TPS month/day (28-day months).
37
+ */
38
+ getComponentsFromDate(date) {
39
+ // Apply 7-hour TPS offset to the Gregorian date
40
+ const offsetMillis = this.TPS_OFFSET_HOURS * 60 * 60 * 1000;
41
+ const offsetDate = new Date(date.getTime() + offsetMillis);
42
+ // Get Gregorian components for the offset date
43
+ const gregComponents = this.gregorian.getComponentsFromDate(offsetDate);
44
+ // Calculate day-of-year (0-indexed) for the offset date
45
+ const yearStart = new Date(Date.UTC(offsetDate.getUTCFullYear(), 0, 1));
46
+ const dayOfYear = Math.floor((offsetDate.getTime() - yearStart.getTime()) / (24 * 60 * 60 * 1000));
47
+ // Convert day-of-year to TPS month/day (each month = 28 days)
48
+ const tpsMonth = Math.floor(dayOfYear / this.TPS_DAYS_PER_MONTH) + 1;
49
+ const tpsDay = (dayOfYear % this.TPS_DAYS_PER_MONTH) + 1;
50
+ return {
51
+ calendar: this.code,
52
+ millennium: gregComponents.millennium,
53
+ century: gregComponents.century,
54
+ year: gregComponents.year,
55
+ month: tpsMonth,
56
+ day: tpsDay,
57
+ hour: gregComponents.hour,
58
+ minute: gregComponents.minute,
59
+ second: gregComponents.second,
60
+ millisecond: gregComponents.millisecond,
61
+ };
62
+ }
63
+ /**
64
+ * Converts TPS components to a Gregorian Date.
65
+ * Converts TPS month/day (28-day months) to day-of-year, then removes 7-hour offset.
66
+ */
67
+ getDateFromComponents(components) {
68
+ // Convert TPS month/day (28-day months) to day-of-year (0-indexed)
69
+ const tpsMonth = components.month ?? 1;
70
+ const tpsDay = components.day ?? 1;
71
+ const dayOfYear = (tpsMonth - 1) * this.TPS_DAYS_PER_MONTH + (tpsDay - 1);
72
+ // Reconstruct full Gregorian year from millennium/century/year
73
+ const m = components.millennium ?? 0;
74
+ const c = components.century ?? 1;
75
+ const y = components.year ?? 0;
76
+ const fullYear = (m - 1) * 1000 + (c - 1) * 100 + y;
77
+ // Create date at start of year and add day-of-year offset
78
+ const dateInYear = new Date(Date.UTC(fullYear, 0, 1));
79
+ dateInYear.setUTCDate(dateInYear.getUTCDate() + dayOfYear);
80
+ // Set time components
81
+ dateInYear.setUTCHours(components.hour ?? 0);
82
+ dateInYear.setUTCMinutes(components.minute ?? 0);
83
+ dateInYear.setUTCSeconds(components.second ?? 0);
84
+ dateInYear.setUTCMilliseconds(components.millisecond ?? 0);
85
+ // Remove 7-hour TPS offset to get back to Gregorian
86
+ const offsetMillis = this.TPS_OFFSET_HOURS * 60 * 60 * 1000;
87
+ return new Date(dateInYear.getTime() - offsetMillis);
88
+ }
89
+ getFromDate(date) {
90
+ const components = this.getComponentsFromDate(date);
91
+ return index_1.TPS.buildTimePart(components);
92
+ }
93
+ /**
94
+ * Parse a TPS date string: "YYYY-MM-DD" where MM is 01-12, DD is 01-28.
95
+ * Optional time: "YYYY-MM-DD HH:MM:SS.mmm"
96
+ */
97
+ parseDate(input, format) {
98
+ const s = input.trim();
99
+ const m = s.match(/^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?$/);
100
+ if (!m) {
101
+ throw new Error(`TpsDriver.parseDate: unsupported format "${input}"`);
102
+ }
103
+ const year = parseInt(m[1], 10);
104
+ const month = parseInt(m[2], 10);
105
+ const day = parseInt(m[3], 10);
106
+ // Validate TPS month/day constraints
107
+ if (month < 1 || month > this.TPS_MONTHS_PER_YEAR) {
108
+ throw new Error(`TpsDriver.parseDate: invalid TPS month ${month} (expected 1-12)`);
109
+ }
110
+ if (day < 1 || day > this.TPS_DAYS_PER_MONTH) {
111
+ throw new Error(`TpsDriver.parseDate: invalid TPS day ${day} (expected 1-${this.TPS_DAYS_PER_MONTH})`);
112
+ }
113
+ const hour = m[4] !== undefined ? parseInt(m[4], 10) : undefined;
114
+ const minute = m[5] !== undefined ? parseInt(m[5], 10) : undefined;
115
+ const second = m[6] !== undefined ? parseInt(m[6], 10) : undefined;
116
+ const millisecond = m[7] !== undefined ? parseInt((m[7] + "000").slice(0, 3), 10) : undefined;
117
+ const comp = {
118
+ calendar: this.code,
119
+ year,
120
+ month,
121
+ day,
122
+ };
123
+ if (hour !== undefined)
124
+ comp.hour = hour;
125
+ if (minute !== undefined)
126
+ comp.minute = minute;
127
+ if (second !== undefined)
128
+ comp.second = second;
129
+ if (millisecond !== undefined)
130
+ comp.millisecond = millisecond;
131
+ return comp;
132
+ }
133
+ /**
134
+ * Format TPS components to "YYYY-MM-DD" where MM is 01-12, DD is 01-28.
135
+ * With time: "YYYY-MM-DD THH:MM:SS.mmm"
136
+ */
137
+ format(components, format) {
138
+ const y = components.year !== undefined
139
+ ? String(components.year).padStart(4, "0")
140
+ : "0000";
141
+ const mo = components.month !== undefined
142
+ ? String(components.month).padStart(2, "0")
143
+ : "01";
144
+ const d = components.day !== undefined
145
+ ? String(components.day).padStart(2, "0")
146
+ : "01";
147
+ let out = `${y}-${mo}-${d}`;
148
+ if (components.hour !== undefined ||
149
+ components.minute !== undefined ||
150
+ components.second !== undefined ||
151
+ components.millisecond !== undefined) {
152
+ const h = components.hour !== undefined
153
+ ? String(components.hour).padStart(2, "0")
154
+ : "00";
155
+ const mi = components.minute !== undefined
156
+ ? String(components.minute).padStart(2, "0")
157
+ : "00";
158
+ const s = components.second !== undefined
159
+ ? String(Math.floor(components.second)).padStart(2, "0")
160
+ : "00";
161
+ const ms = components.millisecond !== undefined
162
+ ? String(components.millisecond).padStart(3, "0")
163
+ : "000";
164
+ out += `T${h}:${mi}:${s}.${ms}`;
165
+ }
166
+ return out;
167
+ }
168
+ /**
169
+ * Validate TPS date string or components.
170
+ * TPS has months 1-12, each with 28 days.
171
+ */
172
+ validate(input) {
173
+ if (typeof input === "string") {
174
+ const valid = /^\d{4}-\d{2}-\d{2}(?:[ T]\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?)?$/.test(input.trim());
175
+ if (!valid)
176
+ return false;
177
+ // Parse and validate constraints
178
+ try {
179
+ this.parseDate(input);
180
+ return true;
181
+ }
182
+ catch {
183
+ return false;
184
+ }
185
+ }
186
+ if (typeof input === "object") {
187
+ return (input.year !== undefined &&
188
+ input.month !== undefined &&
189
+ input.day !== undefined &&
190
+ input.year >= 0 &&
191
+ input.month >= 1 &&
192
+ input.month <= this.TPS_MONTHS_PER_YEAR &&
193
+ input.day >= 1 &&
194
+ input.day <= this.TPS_DAYS_PER_MONTH);
195
+ }
196
+ return false;
197
+ }
198
+ /**
199
+ * Get TPS calendar metadata.
200
+ * TPS has 12 months, each with 28 days.
201
+ */
202
+ getMetadata() {
203
+ return {
204
+ name: "TPS Canonical (28-day months)",
205
+ monthNames: [
206
+ "Month 1",
207
+ "Month 2",
208
+ "Month 3",
209
+ "Month 4",
210
+ "Month 5",
211
+ "Month 6",
212
+ "Month 7",
213
+ "Month 8",
214
+ "Month 9",
215
+ "Month 10",
216
+ "Month 11",
217
+ "Month 12",
218
+ ],
219
+ dayNames: [
220
+ "Sunday",
221
+ "Monday",
222
+ "Tuesday",
223
+ "Wednesday",
224
+ "Thursday",
225
+ "Friday",
226
+ "Saturday",
227
+ ],
228
+ monthsPerYear: this.TPS_MONTHS_PER_YEAR,
229
+ epochYear: 1999,
230
+ isLunar: false,
231
+ };
232
+ }
233
+ }
234
+ exports.TpsDriver = TpsDriver;
235
+ //# sourceMappingURL=tps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tps.js","sourceRoot":"","sources":["../../src/drivers/tps.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,oCAAgF;AAChF,2CAA8C;AAE9C,MAAa,SAAS;IAAtB;QACW,SAAI,GAAG,KAAK,CAAC;QACb,SAAI,GAAG,eAAe,CAAC;QAEhC,wCAAwC;QACvB,cAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACzE,oCAAoC;QACnB,qBAAgB,GAAG,CAAC,CAAC;QACtC,6BAA6B;QACZ,uBAAkB,GAAG,EAAE,CAAC;QACzC,kDAAkD;QACjC,wBAAmB,GAAG,EAAE,CAAC;QAEzB,cAAS,GAAG,IAAI,2BAAe,EAAE,CAAC;IA+OrD,CAAC;IA7OC;;;OAGG;IACH,qBAAqB,CAAC,IAAU;QAC9B,gDAAgD;QAChD,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAC5D,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GA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E;gBACR,QAAQ;gBACR,QAAQ;gBACR,SAAS;gBACT,WAAW;gBACX,UAAU;gBACV,QAAQ;gBACR,UAAU;aACX;YACD,aAAa,EAAE,IAAI,CAAC,mBAAmB;YACvC,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;CACF;AA5PD,8BA4PC"}
@@ -0,0 +1,16 @@
1
+ import { CalendarDriver, TPSComponents, CalendarMetadata } from "../index";
2
+ /**
3
+ * Unix calendar driver. Represents the epoch timestamp in seconds with
4
+ * fractional milliseconds. This mirrors the built-in `CalendarCode.UNIX`
5
+ * behaviour that was previously hard-coded in TPS.
6
+ */
7
+ export declare class UnixDriver implements CalendarDriver {
8
+ readonly code: string;
9
+ getComponentsFromDate(date: Date): Partial<TPSComponents>;
10
+ getDateFromComponents(components: Partial<TPSComponents>): Date;
11
+ getFromDate(date: Date): string;
12
+ parseDate(input: string, format?: string): Partial<TPSComponents>;
13
+ format(components: Partial<TPSComponents>, format?: string): string;
14
+ validate(input: string | Partial<TPSComponents>): boolean;
15
+ getMetadata(): CalendarMetadata;
16
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnixDriver = void 0;
4
+ const index_1 = require("../index");
5
+ /**
6
+ * Unix calendar driver. Represents the epoch timestamp in seconds with
7
+ * fractional milliseconds. This mirrors the built-in `CalendarCode.UNIX`
8
+ * behaviour that was previously hard-coded in TPS.
9
+ */
10
+ class UnixDriver {
11
+ constructor() {
12
+ this.code = "unix";
13
+ }
14
+ getComponentsFromDate(date) {
15
+ const s = (date.getTime() / 1000).toFixed(3);
16
+ return { calendar: this.code, unixSeconds: parseFloat(s) };
17
+ }
18
+ getDateFromComponents(components) {
19
+ // prefer an explicit unixSeconds value when available
20
+ if (components.unixSeconds !== undefined) {
21
+ return new Date(components.unixSeconds * 1000);
22
+ }
23
+ // otherwise attempt to derive a date from the other temporal fields by
24
+ // round-tripping through the core TPS logic. This is a little heavier but
25
+ // keeps the Unix driver useful when callers supply a full set of
26
+ // millennium/century/... values instead of a raw epoch.
27
+ try {
28
+ // The toURI helper will fill in the required time tokens and defaults.
29
+ const tpsString = index_1.TPS.buildTimePart(components);
30
+ const date = index_1.TPS.toDate(tpsString);
31
+ if (!date) {
32
+ throw new Error("unable to convert components to Date");
33
+ }
34
+ return date;
35
+ }
36
+ catch (err) {
37
+ throw new Error("UnixDriver.toGregorian: missing unixSeconds and unable to compute date");
38
+ }
39
+ }
40
+ getFromDate(date) {
41
+ const comp = this.getComponentsFromDate(date);
42
+ return index_1.TPS.buildTimePart(comp);
43
+ }
44
+ parseDate(input, format) {
45
+ const s = input.trim();
46
+ // Accept simple numeric timestamps with optional fractional part
47
+ if (!/^[0-9]+(?:\.[0-9]+)?$/.test(s)) {
48
+ throw new Error(`UnixDriver.parseDate: unsupported format "${input}"`);
49
+ }
50
+ return { calendar: this.code, unixSeconds: parseFloat(s) };
51
+ }
52
+ format(components, format) {
53
+ if (components.unixSeconds === undefined) {
54
+ throw new Error("UnixDriver.format: missing unixSeconds");
55
+ }
56
+ return new Date(components.unixSeconds * 1000).toISOString();
57
+ }
58
+ validate(input) {
59
+ if (typeof input === "string") {
60
+ return /^[0-9]+(?:\.[0-9]+)?$/.test(input.trim());
61
+ }
62
+ if (typeof input === "object") {
63
+ return typeof input.unixSeconds === "number" && !isNaN(input.unixSeconds);
64
+ }
65
+ return false;
66
+ }
67
+ getMetadata() {
68
+ return {
69
+ name: "Unix Epoch",
70
+ // there is no concept of months; include minimal info
71
+ monthsPerYear: 0,
72
+ };
73
+ }
74
+ }
75
+ exports.UnixDriver = UnixDriver;
76
+ //# sourceMappingURL=unix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unix.js","sourceRoot":"","sources":["../../src/drivers/unix.ts"],"names":[],"mappings":";;;AAAA,oCAAgF;AAEhF;;;;GAIG;AACH,MAAa,UAAU;IAAvB;QACW,SAAI,GAAW,MAAM,CAAC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