dce-reactkit 4.2.4-beta-timestamp.1 → 4.2.4-beta-timestamp.2
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/package.json
CHANGED
|
@@ -42,7 +42,7 @@ const getTimestampFromTimeInfoInET = (
|
|
|
42
42
|
const hh = padZerosLeft(hour, 2);
|
|
43
43
|
const min = padZerosLeft(minute, 2);
|
|
44
44
|
|
|
45
|
-
// Use Intl.DateTimeFormat to get the ET offset
|
|
45
|
+
// Use Intl.DateTimeFormat to get the ET offset and ET components
|
|
46
46
|
const dateForET = new Date(Date.UTC(year, month - 1, day, hour, minute, 0));
|
|
47
47
|
const options: Intl.DateTimeFormatOptions = {
|
|
48
48
|
timeZone: 'America/New_York',
|
|
@@ -53,6 +53,7 @@ const getTimestampFromTimeInfoInET = (
|
|
|
53
53
|
minute: '2-digit',
|
|
54
54
|
second: '2-digit',
|
|
55
55
|
hour12: false,
|
|
56
|
+
timeZoneName: 'shortOffset',
|
|
56
57
|
};
|
|
57
58
|
const parts: Intl.DateTimeFormatPart[] = new Intl.DateTimeFormat('en-US', options).formatToParts(dateForET);
|
|
58
59
|
const etYear: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
|
|
@@ -73,17 +74,29 @@ const getTimestampFromTimeInfoInET = (
|
|
|
73
74
|
const etSecond: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
|
|
74
75
|
return p.type === 'second';
|
|
75
76
|
})?.value;
|
|
77
|
+
const tzName: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
|
|
78
|
+
return p.type === 'timeZoneName';
|
|
79
|
+
})?.value;
|
|
76
80
|
|
|
77
|
-
//
|
|
78
|
-
if (!etYear || !etMonth || !etDay || !etHour || !etMinute || !etSecond) {
|
|
81
|
+
// Validate we got everything we need
|
|
82
|
+
if (!etYear || !etMonth || !etDay || !etHour || !etMinute || !etSecond || !tzName) {
|
|
79
83
|
throw new ErrorWithCode(
|
|
80
84
|
'Failed to parse date parts from Intl.DateTimeFormat',
|
|
81
85
|
ReactKitErrorCode.ETTimestampInvalid,
|
|
82
86
|
);
|
|
83
87
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
88
|
+
|
|
89
|
+
// Extract numeric offset from "GMT-4" or "UTC-5"
|
|
90
|
+
const offsetNum = Number(tzName.replace(/^(GMT|UTC)/, ''));
|
|
91
|
+
const sign = offsetNum >= 0 ? '+' : '-';
|
|
92
|
+
const offset = `${sign}${padZerosLeft(Math.abs(offsetNum), 2)}:00`;
|
|
93
|
+
|
|
94
|
+
// Build ISO string with offset
|
|
95
|
+
const etDateString = `${etYear}-${etMonth}-${etDay}T${etHour}:${etMinute}:${etSecond}${offset}`;
|
|
96
|
+
|
|
97
|
+
// Parse into ET timestamp
|
|
98
|
+
const etDate = new Date(etDateString);
|
|
99
|
+
const timestamp = etDate.getTime();
|
|
87
100
|
|
|
88
101
|
// Verify that the timestamp is correct
|
|
89
102
|
const timeInfoInET = getTimeInfoInET(timestamp);
|
|
@@ -95,7 +108,9 @@ const getTimestampFromTimeInfoInET = (
|
|
|
95
108
|
|| timeInfoInET.minute !== minute
|
|
96
109
|
) {
|
|
97
110
|
throw new ErrorWithCode(
|
|
98
|
-
`Timestamp mismatch: expected ${year}-${mm}-${dd} ${hh}:${min},
|
|
111
|
+
`Timestamp mismatch: expected ${year}-${mm}-${dd} ${hh}:${min}, `
|
|
112
|
+
+ `got ${timeInfoInET.year}-${padZerosLeft(timeInfoInET.month, 2)}-${padZerosLeft(timeInfoInET.day, 2)} `
|
|
113
|
+
+ `${padZerosLeft(timeInfoInET.hour, 2)}:${padZerosLeft(timeInfoInET.minute, 2)}`,
|
|
99
114
|
ReactKitErrorCode.ETTimestampInvalid,
|
|
100
115
|
);
|
|
101
116
|
}
|