dce-reactkit 4.2.3 → 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/dist/cjs/index.js +52 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +52 -9
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/getTimestampFromTimeInfoInET.ts +58 -10
package/dist/cjs/index.js
CHANGED
|
@@ -16398,21 +16398,62 @@ 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, _g;
|
|
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 and ET components
|
|
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
|
+
timeZoneName: 'shortOffset',
|
|
16421
|
+
};
|
|
16422
|
+
const parts = new Intl.DateTimeFormat('en-US', options).formatToParts(dateForET);
|
|
16423
|
+
const etYear = (_a = parts.find((p) => {
|
|
16424
|
+
return p.type === 'year';
|
|
16425
|
+
})) === null || _a === void 0 ? void 0 : _a.value;
|
|
16426
|
+
const etMonth = (_b = parts.find((p) => {
|
|
16427
|
+
return p.type === 'month';
|
|
16428
|
+
})) === null || _b === void 0 ? void 0 : _b.value;
|
|
16429
|
+
const etDay = (_c = parts.find((p) => {
|
|
16430
|
+
return p.type === 'day';
|
|
16431
|
+
})) === null || _c === void 0 ? void 0 : _c.value;
|
|
16432
|
+
const etHour = (_d = parts.find((p) => {
|
|
16433
|
+
return p.type === 'hour';
|
|
16434
|
+
})) === null || _d === void 0 ? void 0 : _d.value;
|
|
16435
|
+
const etMinute = (_e = parts.find((p) => {
|
|
16436
|
+
return p.type === 'minute';
|
|
16437
|
+
})) === null || _e === void 0 ? void 0 : _e.value;
|
|
16438
|
+
const etSecond = (_f = parts.find((p) => {
|
|
16439
|
+
return p.type === 'second';
|
|
16440
|
+
})) === null || _f === void 0 ? void 0 : _f.value;
|
|
16441
|
+
const tzName = (_g = parts.find((p) => {
|
|
16442
|
+
return p.type === 'timeZoneName';
|
|
16443
|
+
})) === null || _g === void 0 ? void 0 : _g.value;
|
|
16444
|
+
// Validate we got everything we need
|
|
16445
|
+
if (!etYear || !etMonth || !etDay || !etHour || !etMinute || !etSecond || !tzName) {
|
|
16446
|
+
throw new ErrorWithCode('Failed to parse date parts from Intl.DateTimeFormat', ReactKitErrorCode$1.ETTimestampInvalid);
|
|
16447
|
+
}
|
|
16448
|
+
// Extract numeric offset from "GMT-4" or "UTC-5"
|
|
16449
|
+
const offsetNum = Number(tzName.replace(/^(GMT|UTC)/, ''));
|
|
16450
|
+
const sign = offsetNum >= 0 ? '+' : '-';
|
|
16451
|
+
const offset = `${sign}${padZerosLeft(Math.abs(offsetNum), 2)}:00`;
|
|
16452
|
+
// Build ISO string with offset
|
|
16453
|
+
const etDateString = `${etYear}-${etMonth}-${etDay}T${etHour}:${etMinute}:${etSecond}${offset}`;
|
|
16454
|
+
// Parse into ET timestamp
|
|
16455
|
+
const etDate = new Date(etDateString);
|
|
16456
|
+
const timestamp = etDate.getTime();
|
|
16416
16457
|
// Verify that the timestamp is correct
|
|
16417
16458
|
const timeInfoInET = getTimeInfoInET(timestamp);
|
|
16418
16459
|
if (timeInfoInET.year !== year
|
|
@@ -16420,7 +16461,9 @@ const getTimestampFromTimeInfoInET = (opts) => {
|
|
|
16420
16461
|
|| timeInfoInET.day !== day
|
|
16421
16462
|
|| timeInfoInET.hour !== hour
|
|
16422
16463
|
|| timeInfoInET.minute !== minute) {
|
|
16423
|
-
throw new ErrorWithCode(`Timestamp mismatch: expected ${year}-${mm}-${dd} ${hh}:${min},
|
|
16464
|
+
throw new ErrorWithCode(`Timestamp mismatch: expected ${year}-${mm}-${dd} ${hh}:${min}, `
|
|
16465
|
+
+ `got ${timeInfoInET.year}-${padZerosLeft(timeInfoInET.month, 2)}-${padZerosLeft(timeInfoInET.day, 2)} `
|
|
16466
|
+
+ `${padZerosLeft(timeInfoInET.hour, 2)}:${padZerosLeft(timeInfoInET.minute, 2)}`, ReactKitErrorCode$1.ETTimestampInvalid);
|
|
16424
16467
|
}
|
|
16425
16468
|
// Valid! Return the timestamp
|
|
16426
16469
|
return timestamp;
|