@nextera.one/tps-standard 0.5.2 → 0.5.33
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/dist/drivers/gregorian.d.ts +1 -1
- package/dist/drivers/gregorian.js +50 -35
- package/dist/drivers/gregorian.js.map +1 -1
- package/dist/drivers/hijri.d.ts +42 -0
- package/dist/drivers/hijri.js +281 -0
- package/dist/drivers/hijri.js.map +1 -0
- package/dist/drivers/holocene.d.ts +25 -0
- package/dist/drivers/holocene.js +132 -0
- package/dist/drivers/holocene.js.map +1 -0
- package/dist/drivers/julian.d.ts +33 -0
- package/dist/drivers/julian.js +225 -0
- package/dist/drivers/julian.js.map +1 -0
- package/dist/drivers/persian.d.ts +33 -0
- package/dist/drivers/persian.js +269 -0
- package/dist/drivers/persian.js.map +1 -0
- package/dist/drivers/tps.d.ts +4 -4
- package/dist/drivers/tps.js +58 -44
- package/dist/drivers/tps.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +37 -63
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
- package/src/drivers/gregorian.ts +71 -38
- package/src/drivers/hijri.ts +322 -0
- package/src/drivers/holocene.ts +152 -0
- package/src/drivers/julian.ts +255 -0
- package/src/drivers/persian.ts +298 -0
- package/src/drivers/tps.ts +82 -51
- package/src/index.ts +38 -78
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PersianDriver = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Persian (Jalali / Solar Hijri) Calendar Driver
|
|
6
|
+
*
|
|
7
|
+
* Calendar characteristics:
|
|
8
|
+
* - Solar calendar used in Iran and Afghanistan
|
|
9
|
+
* - Year 1 started in 622 CE (same epoch as Islamic Hijri, but solar-based)
|
|
10
|
+
* - 6 months of 31 days, 5 months of 30 days, 1 month of 29 (30 in leap)
|
|
11
|
+
* - Current year ≈ Gregorian year − 621
|
|
12
|
+
*
|
|
13
|
+
* Conversion uses Julian Day Number algorithms based on jalaali-js.
|
|
14
|
+
*/
|
|
15
|
+
const index_1 = require("../index");
|
|
16
|
+
class PersianDriver {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.code = "per";
|
|
19
|
+
this.name = "Persian (Jalali/Solar Hijri)";
|
|
20
|
+
this.MONTH_NAMES = [
|
|
21
|
+
"Farvardin",
|
|
22
|
+
"Ordibehesht",
|
|
23
|
+
"Khordad",
|
|
24
|
+
"Tir",
|
|
25
|
+
"Mordad",
|
|
26
|
+
"Shahrivar",
|
|
27
|
+
"Mehr",
|
|
28
|
+
"Aban",
|
|
29
|
+
"Azar",
|
|
30
|
+
"Dey",
|
|
31
|
+
"Bahman",
|
|
32
|
+
"Esfand",
|
|
33
|
+
];
|
|
34
|
+
this.MONTH_NAMES_SHORT = [
|
|
35
|
+
"Far",
|
|
36
|
+
"Ord",
|
|
37
|
+
"Kho",
|
|
38
|
+
"Tir",
|
|
39
|
+
"Mor",
|
|
40
|
+
"Sha",
|
|
41
|
+
"Meh",
|
|
42
|
+
"Aba",
|
|
43
|
+
"Aza",
|
|
44
|
+
"Dey",
|
|
45
|
+
"Bah",
|
|
46
|
+
"Esf",
|
|
47
|
+
];
|
|
48
|
+
this.DAY_NAMES = [
|
|
49
|
+
"Yekshanbeh",
|
|
50
|
+
"Doshanbeh",
|
|
51
|
+
"Seshanbeh",
|
|
52
|
+
"Chaharshanbeh",
|
|
53
|
+
"Panjshanbeh",
|
|
54
|
+
"Jomeh",
|
|
55
|
+
"Shanbeh",
|
|
56
|
+
];
|
|
57
|
+
/** Days per month (non-leap): 6×31 + 5×30 + 1×29 = 365 */
|
|
58
|
+
this.DAYS_IN_MONTH = [
|
|
59
|
+
31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29,
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
// ── CalendarDriver interface ──────────────────────────────────────────
|
|
63
|
+
getComponentsFromDate(date) {
|
|
64
|
+
const jdn = this.gregorianToJdn(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate());
|
|
65
|
+
const { jy, jm, jd } = this.jdnToPersian(jdn);
|
|
66
|
+
return {
|
|
67
|
+
calendar: this.code,
|
|
68
|
+
millennium: Math.floor(jy / 1000) + 1,
|
|
69
|
+
century: Math.floor((jy % 1000) / 100) + 1,
|
|
70
|
+
year: jy % 100,
|
|
71
|
+
month: jm,
|
|
72
|
+
day: jd,
|
|
73
|
+
hour: date.getUTCHours(),
|
|
74
|
+
minute: date.getUTCMinutes(),
|
|
75
|
+
second: date.getUTCSeconds(),
|
|
76
|
+
millisecond: date.getUTCMilliseconds(),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
getDateFromComponents(components) {
|
|
80
|
+
// Reconstruct full Persian year from millennium/century/year if available
|
|
81
|
+
let jy;
|
|
82
|
+
if (components.millennium !== undefined) {
|
|
83
|
+
const m = components.millennium ?? 0;
|
|
84
|
+
const c = components.century ?? 1;
|
|
85
|
+
const y = components.year ?? 0;
|
|
86
|
+
jy = (m - 1) * 1000 + (c - 1) * 100 + y;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
jy = components.year ?? 1;
|
|
90
|
+
}
|
|
91
|
+
const jm = components.month ?? 1;
|
|
92
|
+
const jd = components.day ?? 1;
|
|
93
|
+
const jdn = this.persianToJdn(jy, jm, jd);
|
|
94
|
+
const { gy, gm, gd } = this.jdnToGregorian(jdn);
|
|
95
|
+
return new Date(Date.UTC(gy, gm - 1, gd, components.hour ?? 0, components.minute ?? 0, Math.floor(components.second ?? 0), components.millisecond ?? 0));
|
|
96
|
+
}
|
|
97
|
+
getFromDate(date) {
|
|
98
|
+
const comp = this.getComponentsFromDate(date);
|
|
99
|
+
return index_1.TPS.buildTimePart(comp);
|
|
100
|
+
}
|
|
101
|
+
parseDate(input, format) {
|
|
102
|
+
const trimmed = input.trim();
|
|
103
|
+
// Short format: 19/10/1404 or 1404/10/19
|
|
104
|
+
if (format === "short" ||
|
|
105
|
+
(trimmed.includes("/") && trimmed.split("/")[0].length <= 2)) {
|
|
106
|
+
const parts = trimmed.split("/").map(Number);
|
|
107
|
+
let fullYear, month, day;
|
|
108
|
+
if (parts[0] > 31) {
|
|
109
|
+
[fullYear, month, day] = parts;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
[day, month, fullYear] = parts;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
calendar: this.code,
|
|
116
|
+
millennium: Math.floor(fullYear / 1000) + 1,
|
|
117
|
+
century: Math.floor((fullYear % 1000) / 100) + 1,
|
|
118
|
+
year: fullYear % 100,
|
|
119
|
+
month,
|
|
120
|
+
day,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// ISO-like: 1404-10-19 [HH:MM:SS]
|
|
124
|
+
const segments = trimmed.split(/[\s,T]+/);
|
|
125
|
+
const [parsedYear, month, day] = segments[0].split(/[-/]/).map(Number);
|
|
126
|
+
const result = { calendar: this.code };
|
|
127
|
+
const fullYear = parsedYear;
|
|
128
|
+
result.millennium = Math.floor(fullYear / 1000) + 1;
|
|
129
|
+
result.century = Math.floor((fullYear % 1000) / 100) + 1;
|
|
130
|
+
result.year = fullYear % 100;
|
|
131
|
+
result.month = month;
|
|
132
|
+
result.day = day;
|
|
133
|
+
if (segments[1]) {
|
|
134
|
+
const [h, m, s] = segments[1].split(":").map(Number);
|
|
135
|
+
result.hour = h ?? 0;
|
|
136
|
+
result.minute = m ?? 0;
|
|
137
|
+
result.second = s ?? 0;
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
format(components, format) {
|
|
142
|
+
const pad = (n) => String(n ?? 0).padStart(2, "0");
|
|
143
|
+
// Reconstruct full year from millennium/century/year
|
|
144
|
+
let fullYear;
|
|
145
|
+
if (components.millennium !== undefined) {
|
|
146
|
+
const m = components.millennium ?? 0;
|
|
147
|
+
const c = components.century ?? 1;
|
|
148
|
+
const y = components.year ?? 0;
|
|
149
|
+
fullYear = (m - 1) * 1000 + (c - 1) * 100 + y;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
fullYear = components.year ?? 0;
|
|
153
|
+
}
|
|
154
|
+
if (format === "short") {
|
|
155
|
+
return `${components.day}/${pad(components.month)}/${fullYear}`;
|
|
156
|
+
}
|
|
157
|
+
if (format === "long") {
|
|
158
|
+
const mn = this.MONTH_NAMES[(components.month ?? 1) - 1];
|
|
159
|
+
return `${components.day} ${mn} ${fullYear}`;
|
|
160
|
+
}
|
|
161
|
+
let out = `${fullYear}-${pad(components.month)}-${pad(components.day)}`;
|
|
162
|
+
if (components.hour !== undefined) {
|
|
163
|
+
out += ` ${pad(components.hour)}:${pad(components.minute)}:${pad(Math.floor(components.second ?? 0))}`;
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
167
|
+
validate(input) {
|
|
168
|
+
let comp;
|
|
169
|
+
if (typeof input === "string") {
|
|
170
|
+
try {
|
|
171
|
+
comp = this.parseDate(input);
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
comp = input;
|
|
179
|
+
}
|
|
180
|
+
const { year, month, day } = comp;
|
|
181
|
+
if (!year || year < 1)
|
|
182
|
+
return false;
|
|
183
|
+
if (!month || month < 1 || month > 12)
|
|
184
|
+
return false;
|
|
185
|
+
if (!day || day < 1)
|
|
186
|
+
return false;
|
|
187
|
+
let max = this.DAYS_IN_MONTH[(month ?? 1) - 1];
|
|
188
|
+
if (month === 12 && this.isLeapYear(year))
|
|
189
|
+
max = 30;
|
|
190
|
+
return day <= max;
|
|
191
|
+
}
|
|
192
|
+
getMetadata() {
|
|
193
|
+
return {
|
|
194
|
+
name: "Persian (Jalali/Solar Hijri)",
|
|
195
|
+
monthNames: this.MONTH_NAMES,
|
|
196
|
+
monthNamesShort: this.MONTH_NAMES_SHORT,
|
|
197
|
+
dayNames: this.DAY_NAMES,
|
|
198
|
+
dayNamesShort: this.DAY_NAMES.map((d) => d.slice(0, 3)),
|
|
199
|
+
isLunar: false,
|
|
200
|
+
monthsPerYear: 12,
|
|
201
|
+
epochYear: 622,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
// ── Internal: leap year (33-year cycle) ───────────────────────────────
|
|
205
|
+
isLeapYear(year) {
|
|
206
|
+
const leapYears = [1, 5, 9, 13, 17, 22, 26, 30];
|
|
207
|
+
const cycle = ((year - 1) % 33) + 1;
|
|
208
|
+
return leapYears.includes(cycle);
|
|
209
|
+
}
|
|
210
|
+
// ── Internal: Julian Day Number algorithms ────────────────────────────
|
|
211
|
+
gregorianToJdn(gy, gm, gd) {
|
|
212
|
+
const a = Math.floor((14 - gm) / 12);
|
|
213
|
+
const y = gy + 4800 - a;
|
|
214
|
+
const m = gm + 12 * a - 3;
|
|
215
|
+
return (gd +
|
|
216
|
+
Math.floor((153 * m + 2) / 5) +
|
|
217
|
+
365 * y +
|
|
218
|
+
Math.floor(y / 4) -
|
|
219
|
+
Math.floor(y / 100) +
|
|
220
|
+
Math.floor(y / 400) -
|
|
221
|
+
32045);
|
|
222
|
+
}
|
|
223
|
+
jdnToGregorian(jdn) {
|
|
224
|
+
const a = jdn + 32044;
|
|
225
|
+
const b = Math.floor((4 * a + 3) / 146097);
|
|
226
|
+
const c = a - Math.floor((146097 * b) / 4);
|
|
227
|
+
const d = Math.floor((4 * c + 3) / 1461);
|
|
228
|
+
const e = c - Math.floor((1461 * d) / 4);
|
|
229
|
+
const m = Math.floor((5 * e + 2) / 153);
|
|
230
|
+
const gd = e - Math.floor((153 * m + 2) / 5) + 1;
|
|
231
|
+
const gm = m + 3 - 12 * Math.floor(m / 10);
|
|
232
|
+
const gy = 100 * b + d - 4800 + Math.floor(m / 10);
|
|
233
|
+
return { gy, gm, gd };
|
|
234
|
+
}
|
|
235
|
+
persianToJdn(jy, jm, jd) {
|
|
236
|
+
const EPOCH = 1948320;
|
|
237
|
+
const epbase = jy - (jy >= 0 ? 474 : 473);
|
|
238
|
+
const epyear = 474 + (epbase % 2820);
|
|
239
|
+
return (jd +
|
|
240
|
+
(jm <= 7 ? (jm - 1) * 31 : (jm - 1) * 30 + 6) +
|
|
241
|
+
Math.floor((epyear * 682 - 110) / 2816) +
|
|
242
|
+
(epyear - 1) * 365 +
|
|
243
|
+
Math.floor(epbase / 2820) * 1029983 +
|
|
244
|
+
EPOCH -
|
|
245
|
+
1);
|
|
246
|
+
}
|
|
247
|
+
jdnToPersian(jdn) {
|
|
248
|
+
const depoch = jdn - this.persianToJdn(475, 1, 1);
|
|
249
|
+
const cycle = Math.floor(depoch / 1029983);
|
|
250
|
+
const cyear = depoch % 1029983;
|
|
251
|
+
let ycycle;
|
|
252
|
+
if (cyear === 1029982) {
|
|
253
|
+
ycycle = 2820;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
const aux1 = Math.floor(cyear / 366);
|
|
257
|
+
const aux2 = cyear % 366;
|
|
258
|
+
ycycle =
|
|
259
|
+
Math.floor((2134 * aux1 + 2816 * aux2 + 2815) / 1028522) + aux1 + 1;
|
|
260
|
+
}
|
|
261
|
+
const jy = ycycle + 2820 * cycle + 474;
|
|
262
|
+
const yday = jdn - this.persianToJdn(jy, 1, 1) + 1;
|
|
263
|
+
const jm = yday <= 186 ? Math.ceil(yday / 31) : Math.ceil((yday - 6) / 30);
|
|
264
|
+
const jd = jdn - this.persianToJdn(jy, jm, 1) + 1;
|
|
265
|
+
return { jy: jy <= 0 ? jy - 1 : jy, jm, jd };
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
exports.PersianDriver = PersianDriver;
|
|
269
|
+
//# sourceMappingURL=persian.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persian.js","sourceRoot":"","sources":["../../src/drivers/persian.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,oCAAg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AG,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;QACxE,CAAC;QACD,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,GAAG,CAAC;QACvC,MAAM,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QACnD,MAAM,EAAE,GAAG,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QAC3E,MAAM,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QAClD,OAAO,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;IAC/C,CAAC;CACF;AA5RD,sCA4RC"}
|
package/dist/drivers/tps.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 3. Convert day-of-year to TPS month/day (each month = 28 days)
|
|
13
13
|
* 4. Preserve millennium/century/year structure
|
|
14
14
|
*/
|
|
15
|
-
import { CalendarDriver, CalendarMetadata, TPSComponents } from
|
|
15
|
+
import { CalendarDriver, CalendarMetadata, TPSComponents } from "../index";
|
|
16
16
|
export declare class TpsDriver implements CalendarDriver {
|
|
17
17
|
readonly code = "tps";
|
|
18
18
|
readonly name = "TPS Canonical";
|
|
@@ -33,18 +33,18 @@ export declare class TpsDriver implements CalendarDriver {
|
|
|
33
33
|
getDateFromComponents(components: Partial<TPSComponents>): Date;
|
|
34
34
|
getFromDate(date: Date): string;
|
|
35
35
|
/**
|
|
36
|
-
* Parse a TPS date string: "YYYY-MM-DD" where MM is 01-
|
|
36
|
+
* Parse a TPS date string: "YYYY-MM-DD" where MM is 01-12, DD is 01-28.
|
|
37
37
|
* Optional time: "YYYY-MM-DD HH:MM:SS.mmm"
|
|
38
38
|
*/
|
|
39
39
|
parseDate(input: string, format?: string): Partial<TPSComponents>;
|
|
40
40
|
/**
|
|
41
|
-
* Format TPS components to "YYYY-MM-DD" where MM is 01-
|
|
41
|
+
* Format TPS components to "YYYY-MM-DD" where MM is 01-12, DD is 01-28.
|
|
42
42
|
* With time: "YYYY-MM-DD THH:MM:SS.mmm"
|
|
43
43
|
*/
|
|
44
44
|
format(components: Partial<TPSComponents>, format?: string): string;
|
|
45
45
|
/**
|
|
46
46
|
* Validate TPS date string or components.
|
|
47
|
-
* TPS has months 1-
|
|
47
|
+
* TPS has months 1-12, each with 28 days.
|
|
48
48
|
*/
|
|
49
49
|
validate(input: string | Partial<TPSComponents>): boolean;
|
|
50
50
|
/**
|
package/dist/drivers/tps.js
CHANGED
|
@@ -19,8 +19,8 @@ const index_1 = require("../index");
|
|
|
19
19
|
const gregorian_1 = require("./gregorian");
|
|
20
20
|
class TpsDriver {
|
|
21
21
|
constructor() {
|
|
22
|
-
this.code =
|
|
23
|
-
this.name =
|
|
22
|
+
this.code = "tps";
|
|
23
|
+
this.name = "TPS Canonical";
|
|
24
24
|
// TPS Epoch: August 11, 1999, 00:00 UTC
|
|
25
25
|
this.TPS_EPOCH = new Date(Date.UTC(1999, 7, 11, 0, 0, 0, 0));
|
|
26
26
|
// TPS is 7 hours ahead of Gregorian
|
|
@@ -66,22 +66,22 @@ class TpsDriver {
|
|
|
66
66
|
*/
|
|
67
67
|
getDateFromComponents(components) {
|
|
68
68
|
// Convert TPS month/day (28-day months) to day-of-year (0-indexed)
|
|
69
|
-
const tpsMonth = components.month
|
|
70
|
-
const tpsDay = components.day
|
|
69
|
+
const tpsMonth = components.month ?? 1;
|
|
70
|
+
const tpsDay = components.day ?? 1;
|
|
71
71
|
const dayOfYear = (tpsMonth - 1) * this.TPS_DAYS_PER_MONTH + (tpsDay - 1);
|
|
72
72
|
// Reconstruct full Gregorian year from millennium/century/year
|
|
73
|
-
const m = components.millennium
|
|
74
|
-
const c = components.century
|
|
75
|
-
const y = components.year
|
|
73
|
+
const m = components.millennium ?? 0;
|
|
74
|
+
const c = components.century ?? 1;
|
|
75
|
+
const y = components.year ?? 0;
|
|
76
76
|
const fullYear = (m - 1) * 1000 + (c - 1) * 100 + y;
|
|
77
77
|
// Create date at start of year and add day-of-year offset
|
|
78
78
|
const dateInYear = new Date(Date.UTC(fullYear, 0, 1));
|
|
79
79
|
dateInYear.setUTCDate(dateInYear.getUTCDate() + dayOfYear);
|
|
80
80
|
// Set time components
|
|
81
|
-
dateInYear.setUTCHours(components.hour
|
|
82
|
-
dateInYear.setUTCMinutes(components.minute
|
|
83
|
-
dateInYear.setUTCSeconds(components.second
|
|
84
|
-
dateInYear.setUTCMilliseconds(components.millisecond
|
|
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
85
|
// Remove 7-hour TPS offset to get back to Gregorian
|
|
86
86
|
const offsetMillis = this.TPS_OFFSET_HOURS * 60 * 60 * 1000;
|
|
87
87
|
return new Date(dateInYear.getTime() - offsetMillis);
|
|
@@ -91,7 +91,7 @@ class TpsDriver {
|
|
|
91
91
|
return index_1.TPS.buildTimePart(components);
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
|
-
* Parse a TPS date string: "YYYY-MM-DD" where MM is 01-
|
|
94
|
+
* Parse a TPS date string: "YYYY-MM-DD" where MM is 01-12, DD is 01-28.
|
|
95
95
|
* Optional time: "YYYY-MM-DD HH:MM:SS.mmm"
|
|
96
96
|
*/
|
|
97
97
|
parseDate(input, format) {
|
|
@@ -113,7 +113,7 @@ class TpsDriver {
|
|
|
113
113
|
const hour = m[4] !== undefined ? parseInt(m[4], 10) : undefined;
|
|
114
114
|
const minute = m[5] !== undefined ? parseInt(m[5], 10) : undefined;
|
|
115
115
|
const second = m[6] !== undefined ? parseInt(m[6], 10) : undefined;
|
|
116
|
-
const millisecond = m[7] !== undefined ? parseInt((m[7] +
|
|
116
|
+
const millisecond = m[7] !== undefined ? parseInt((m[7] + "000").slice(0, 3), 10) : undefined;
|
|
117
117
|
const comp = {
|
|
118
118
|
calendar: this.code,
|
|
119
119
|
year,
|
|
@@ -131,32 +131,46 @@ class TpsDriver {
|
|
|
131
131
|
return comp;
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
|
-
* Format TPS components to "YYYY-MM-DD" where MM is 01-
|
|
134
|
+
* Format TPS components to "YYYY-MM-DD" where MM is 01-12, DD is 01-28.
|
|
135
135
|
* With time: "YYYY-MM-DD THH:MM:SS.mmm"
|
|
136
136
|
*/
|
|
137
137
|
format(components, format) {
|
|
138
|
-
const y = components.year !== undefined
|
|
139
|
-
|
|
140
|
-
|
|
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";
|
|
141
147
|
let out = `${y}-${mo}-${d}`;
|
|
142
148
|
if (components.hour !== undefined ||
|
|
143
149
|
components.minute !== undefined ||
|
|
144
150
|
components.second !== undefined ||
|
|
145
151
|
components.millisecond !== undefined) {
|
|
146
|
-
const h = components.hour !== undefined
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
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";
|
|
150
164
|
out += `T${h}:${mi}:${s}.${ms}`;
|
|
151
165
|
}
|
|
152
166
|
return out;
|
|
153
167
|
}
|
|
154
168
|
/**
|
|
155
169
|
* Validate TPS date string or components.
|
|
156
|
-
* TPS has months 1-
|
|
170
|
+
* TPS has months 1-12, each with 28 days.
|
|
157
171
|
*/
|
|
158
172
|
validate(input) {
|
|
159
|
-
if (typeof input ===
|
|
173
|
+
if (typeof input === "string") {
|
|
160
174
|
const valid = /^\d{4}-\d{2}-\d{2}(?:[ T]\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?)?$/.test(input.trim());
|
|
161
175
|
if (!valid)
|
|
162
176
|
return false;
|
|
@@ -169,7 +183,7 @@ class TpsDriver {
|
|
|
169
183
|
return false;
|
|
170
184
|
}
|
|
171
185
|
}
|
|
172
|
-
if (typeof input ===
|
|
186
|
+
if (typeof input === "object") {
|
|
173
187
|
return (input.year !== undefined &&
|
|
174
188
|
input.month !== undefined &&
|
|
175
189
|
input.day !== undefined &&
|
|
@@ -187,29 +201,29 @@ class TpsDriver {
|
|
|
187
201
|
*/
|
|
188
202
|
getMetadata() {
|
|
189
203
|
return {
|
|
190
|
-
name:
|
|
204
|
+
name: "TPS Canonical (28-day months)",
|
|
191
205
|
monthNames: [
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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",
|
|
204
218
|
],
|
|
205
219
|
dayNames: [
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
220
|
+
"Sunday",
|
|
221
|
+
"Monday",
|
|
222
|
+
"Tuesday",
|
|
223
|
+
"Wednesday",
|
|
224
|
+
"Thursday",
|
|
225
|
+
"Friday",
|
|
226
|
+
"Saturday",
|
|
213
227
|
],
|
|
214
228
|
monthsPerYear: this.TPS_MONTHS_PER_YEAR,
|
|
215
229
|
epochYear: 1999,
|
package/dist/drivers/tps.js.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"tps.js","sourceRoot":"","sources":["../../src/drivers/tps.ts"],"names":[],"mappings":";;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OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,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,IAAI,CAAC,mBAAmB;gBACvC,KAAK,CAAC,GAAG,IAAI,CAAC;gBACd,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,kBAAkB,CACrC,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO;YACL,IAAI,EAAE,+BAA+B;YACrC,UAAU,EAAE;gBACV,SAAS;gBACT,SAAS;gBACT,SAAS;gBACT,SAAS;gBACT,SAAS;gBACT,SAAS;gBACT,SAAS;gBACT,SAAS;gBACT,SAAS;gBACT,UAAU;gBACV,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,IAAI,CAAC,mBAAmB;YACvC,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;CACF;AA5PD,8BA4PC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* TPS: Temporal Positioning System
|
|
3
3
|
* The Universal Protocol for Space-Time Coordinates.
|
|
4
4
|
* @packageDocumentation
|
|
5
|
-
* @version 0.5.
|
|
5
|
+
* @version 0.5.2
|
|
6
6
|
* @license Apache-2.0
|
|
7
7
|
* @copyright 2026 TPS Standards Working Group
|
|
8
8
|
*
|
|
@@ -16,6 +16,7 @@ export declare const DefaultCalendars: {
|
|
|
16
16
|
readonly TPS: "tps";
|
|
17
17
|
readonly GREG: "greg";
|
|
18
18
|
readonly HIJ: "hij";
|
|
19
|
+
readonly PER: "per";
|
|
19
20
|
readonly JUL: "jul";
|
|
20
21
|
readonly HOLO: "holo";
|
|
21
22
|
readonly UNIX: "unix";
|
|
@@ -523,7 +524,6 @@ export declare class TPSUID7RB {
|
|
|
523
524
|
/**
|
|
524
525
|
* Generate a TPS string from a Date and optional location.
|
|
525
526
|
*/
|
|
526
|
-
private static generateTPSString;
|
|
527
527
|
/**
|
|
528
528
|
* Parse epoch milliseconds from a TPS string.
|
|
529
529
|
* Supports both URI format (tps://...) and time-only format (T:greg...)
|