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/esm/index.js CHANGED
@@ -16371,21 +16371,62 @@ const getWordCount = (text) => {
16371
16371
  * @returns Timestamp in milliseconds since epoch
16372
16372
  */
16373
16373
  const getTimestampFromTimeInfoInET = (opts) => {
16374
+ var _a, _b, _c, _d, _e, _f, _g;
16374
16375
  // Destructure opts
16375
16376
  const { year, month, day, hour, minute, } = opts;
16376
- // Determine if the date is in DST in Eastern Time
16377
- const tempDate = new Date(year, month - 1, day);
16378
- const janOffset = new Date(year, 0, 1).getTimezoneOffset();
16379
- const isDST = tempDate.getTimezoneOffset() < janOffset;
16380
- const etOffset = isDST ? '-04:00' : '-05:00';
16381
16377
  // Format with leading zeroes
16382
16378
  const mm = padZerosLeft(month, 2);
16383
16379
  const dd = padZerosLeft(day, 2);
16384
16380
  const hh = padZerosLeft(hour, 2);
16385
16381
  const min = padZerosLeft(minute, 2);
16386
- // Build ET ISO string and convert to UTC timestamp
16387
- const etISOString = `${year}-${mm}-${dd}T${hh}:${min}:00${etOffset}`;
16388
- const timestamp = (new Date(etISOString)).getTime();
16382
+ // Use Intl.DateTimeFormat to get the ET offset and ET components
16383
+ const dateForET = new Date(Date.UTC(year, month - 1, day, hour, minute, 0));
16384
+ const options = {
16385
+ timeZone: 'America/New_York',
16386
+ year: 'numeric',
16387
+ month: '2-digit',
16388
+ day: '2-digit',
16389
+ hour: '2-digit',
16390
+ minute: '2-digit',
16391
+ second: '2-digit',
16392
+ hour12: false,
16393
+ timeZoneName: 'shortOffset',
16394
+ };
16395
+ const parts = new Intl.DateTimeFormat('en-US', options).formatToParts(dateForET);
16396
+ const etYear = (_a = parts.find((p) => {
16397
+ return p.type === 'year';
16398
+ })) === null || _a === void 0 ? void 0 : _a.value;
16399
+ const etMonth = (_b = parts.find((p) => {
16400
+ return p.type === 'month';
16401
+ })) === null || _b === void 0 ? void 0 : _b.value;
16402
+ const etDay = (_c = parts.find((p) => {
16403
+ return p.type === 'day';
16404
+ })) === null || _c === void 0 ? void 0 : _c.value;
16405
+ const etHour = (_d = parts.find((p) => {
16406
+ return p.type === 'hour';
16407
+ })) === null || _d === void 0 ? void 0 : _d.value;
16408
+ const etMinute = (_e = parts.find((p) => {
16409
+ return p.type === 'minute';
16410
+ })) === null || _e === void 0 ? void 0 : _e.value;
16411
+ const etSecond = (_f = parts.find((p) => {
16412
+ return p.type === 'second';
16413
+ })) === null || _f === void 0 ? void 0 : _f.value;
16414
+ const tzName = (_g = parts.find((p) => {
16415
+ return p.type === 'timeZoneName';
16416
+ })) === null || _g === void 0 ? void 0 : _g.value;
16417
+ // Validate we got everything we need
16418
+ if (!etYear || !etMonth || !etDay || !etHour || !etMinute || !etSecond || !tzName) {
16419
+ throw new ErrorWithCode('Failed to parse date parts from Intl.DateTimeFormat', ReactKitErrorCode$1.ETTimestampInvalid);
16420
+ }
16421
+ // Extract numeric offset from "GMT-4" or "UTC-5"
16422
+ const offsetNum = Number(tzName.replace(/^(GMT|UTC)/, ''));
16423
+ const sign = offsetNum >= 0 ? '+' : '-';
16424
+ const offset = `${sign}${padZerosLeft(Math.abs(offsetNum), 2)}:00`;
16425
+ // Build ISO string with offset
16426
+ const etDateString = `${etYear}-${etMonth}-${etDay}T${etHour}:${etMinute}:${etSecond}${offset}`;
16427
+ // Parse into ET timestamp
16428
+ const etDate = new Date(etDateString);
16429
+ const timestamp = etDate.getTime();
16389
16430
  // Verify that the timestamp is correct
16390
16431
  const timeInfoInET = getTimeInfoInET(timestamp);
16391
16432
  if (timeInfoInET.year !== year
@@ -16393,7 +16434,9 @@ const getTimestampFromTimeInfoInET = (opts) => {
16393
16434
  || timeInfoInET.day !== day
16394
16435
  || timeInfoInET.hour !== hour
16395
16436
  || timeInfoInET.minute !== minute) {
16396
- throw new ErrorWithCode(`Timestamp mismatch: expected ${year}-${mm}-${dd} ${hh}:${min}, got ${timeInfoInET.year}-${padZerosLeft(timeInfoInET.month, 2)}-${padZerosLeft(timeInfoInET.day, 2)} ${padZerosLeft(timeInfoInET.hour, 2)}:${padZerosLeft(timeInfoInET.minute, 2)}`, ReactKitErrorCode$1.ETTimestampInvalid);
16437
+ throw new ErrorWithCode(`Timestamp mismatch: expected ${year}-${mm}-${dd} ${hh}:${min}, `
16438
+ + `got ${timeInfoInET.year}-${padZerosLeft(timeInfoInET.month, 2)}-${padZerosLeft(timeInfoInET.day, 2)} `
16439
+ + `${padZerosLeft(timeInfoInET.hour, 2)}:${padZerosLeft(timeInfoInET.minute, 2)}`, ReactKitErrorCode$1.ETTimestampInvalid);
16397
16440
  }
16398
16441
  // Valid! Return the timestamp
16399
16442
  return timestamp;