dce-reactkit 4.2.3 → 4.2.4-beta-timestamp.1
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/cjs/index.js
CHANGED
|
@@ -16398,21 +16398,52 @@ const getWordCount = (text) => {
|
|
|
16398
16398
|
* @returns Timestamp in milliseconds since epoch
|
|
16399
16399
|
*/
|
|
16400
16400
|
const getTimestampFromTimeInfoInET = (opts) => {
|
|
16401
|
+
var _a, _b, _c, _d, _e, _f;
|
|
16401
16402
|
// Destructure opts
|
|
16402
16403
|
const { year, month, day, hour, minute, } = opts;
|
|
16403
|
-
// Determine if the date is in DST in Eastern Time
|
|
16404
|
-
const tempDate = new Date(year, month - 1, day);
|
|
16405
|
-
const janOffset = new Date(year, 0, 1).getTimezoneOffset();
|
|
16406
|
-
const isDST = tempDate.getTimezoneOffset() < janOffset;
|
|
16407
|
-
const etOffset = isDST ? '-04:00' : '-05:00';
|
|
16408
16404
|
// Format with leading zeroes
|
|
16409
16405
|
const mm = padZerosLeft(month, 2);
|
|
16410
16406
|
const dd = padZerosLeft(day, 2);
|
|
16411
16407
|
const hh = padZerosLeft(hour, 2);
|
|
16412
16408
|
const min = padZerosLeft(minute, 2);
|
|
16413
|
-
//
|
|
16414
|
-
const
|
|
16415
|
-
const
|
|
16409
|
+
// Use Intl.DateTimeFormat to get the ET offset for the given date
|
|
16410
|
+
const dateForET = new Date(Date.UTC(year, month - 1, day, hour, minute, 0));
|
|
16411
|
+
const options = {
|
|
16412
|
+
timeZone: 'America/New_York',
|
|
16413
|
+
year: 'numeric',
|
|
16414
|
+
month: '2-digit',
|
|
16415
|
+
day: '2-digit',
|
|
16416
|
+
hour: '2-digit',
|
|
16417
|
+
minute: '2-digit',
|
|
16418
|
+
second: '2-digit',
|
|
16419
|
+
hour12: false,
|
|
16420
|
+
};
|
|
16421
|
+
const parts = new Intl.DateTimeFormat('en-US', options).formatToParts(dateForET);
|
|
16422
|
+
const etYear = (_a = parts.find((p) => {
|
|
16423
|
+
return p.type === 'year';
|
|
16424
|
+
})) === null || _a === void 0 ? void 0 : _a.value;
|
|
16425
|
+
const etMonth = (_b = parts.find((p) => {
|
|
16426
|
+
return p.type === 'month';
|
|
16427
|
+
})) === null || _b === void 0 ? void 0 : _b.value;
|
|
16428
|
+
const etDay = (_c = parts.find((p) => {
|
|
16429
|
+
return p.type === 'day';
|
|
16430
|
+
})) === null || _c === void 0 ? void 0 : _c.value;
|
|
16431
|
+
const etHour = (_d = parts.find((p) => {
|
|
16432
|
+
return p.type === 'hour';
|
|
16433
|
+
})) === null || _d === void 0 ? void 0 : _d.value;
|
|
16434
|
+
const etMinute = (_e = parts.find((p) => {
|
|
16435
|
+
return p.type === 'minute';
|
|
16436
|
+
})) === null || _e === void 0 ? void 0 : _e.value;
|
|
16437
|
+
const etSecond = (_f = parts.find((p) => {
|
|
16438
|
+
return p.type === 'second';
|
|
16439
|
+
})) === null || _f === void 0 ? void 0 : _f.value;
|
|
16440
|
+
// Build ET date string and parse as if local, then get UTC timestamp
|
|
16441
|
+
if (!etYear || !etMonth || !etDay || !etHour || !etMinute || !etSecond) {
|
|
16442
|
+
throw new ErrorWithCode('Failed to parse date parts from Intl.DateTimeFormat', ReactKitErrorCode$1.ETTimestampInvalid);
|
|
16443
|
+
}
|
|
16444
|
+
const etDateString = `${etYear}-${etMonth}-${etDay}T${etHour}:${etMinute}:${etSecond}`;
|
|
16445
|
+
const etDate = new Date(etDateString);
|
|
16446
|
+
const timestamp = etDate.getTime();
|
|
16416
16447
|
// Verify that the timestamp is correct
|
|
16417
16448
|
const timeInfoInET = getTimeInfoInET(timestamp);
|
|
16418
16449
|
if (timeInfoInET.year !== year
|