dce-reactkit 4.2.4-beta-timestamp.2 → 4.2.4-beta.heat-seek.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 +100 -63
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/helpers/getTimestampFromTimeInfoInET.d.ts +1 -1
- package/dist/esm/index.js +100 -63
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/helpers/getTimestampFromTimeInfoInET.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/helpers/getTimestampFromTimeInfoInET.ts +123 -69
package/dist/cjs/index.js
CHANGED
|
@@ -16385,6 +16385,58 @@ const getWordCount = (text) => {
|
|
|
16385
16385
|
};
|
|
16386
16386
|
|
|
16387
16387
|
// Import shared types
|
|
16388
|
+
/*----------------------------------------*/
|
|
16389
|
+
/* --------------- Helpers -------------- */
|
|
16390
|
+
/*----------------------------------------*/
|
|
16391
|
+
/**
|
|
16392
|
+
* Check if a timestamp is valid
|
|
16393
|
+
* @param opts object containing all arguments
|
|
16394
|
+
* @param opts.timestamp Timestamp in milliseconds since epoch
|
|
16395
|
+
* @param opts.expectedYear Expected year
|
|
16396
|
+
* @param opts.expectedMonth Expected month
|
|
16397
|
+
* @param opts.expectedDay Expected day
|
|
16398
|
+
* @param opts.expectedHour Expected hour
|
|
16399
|
+
* @param opts.expectedMinute Expected minute
|
|
16400
|
+
* @returns 1 if the timestamp needs to be increased, -1 if it needs to be decreased, 0 if it is valid
|
|
16401
|
+
*/
|
|
16402
|
+
const checkTimestamp = (opts) => {
|
|
16403
|
+
const { timestamp, expectedYear, expectedMonth, expectedDay, expectedHour, expectedMinute, } = opts;
|
|
16404
|
+
const timeInfoInET = getTimeInfoInET(timestamp);
|
|
16405
|
+
if (timeInfoInET.year < expectedYear) {
|
|
16406
|
+
return 1;
|
|
16407
|
+
}
|
|
16408
|
+
if (timeInfoInET.year > expectedYear) {
|
|
16409
|
+
return -1;
|
|
16410
|
+
}
|
|
16411
|
+
if (timeInfoInET.month < expectedMonth) {
|
|
16412
|
+
return 1;
|
|
16413
|
+
}
|
|
16414
|
+
if (timeInfoInET.month > expectedMonth) {
|
|
16415
|
+
return -1;
|
|
16416
|
+
}
|
|
16417
|
+
if (timeInfoInET.day < expectedDay) {
|
|
16418
|
+
return 1;
|
|
16419
|
+
}
|
|
16420
|
+
if (timeInfoInET.day > expectedDay) {
|
|
16421
|
+
return -1;
|
|
16422
|
+
}
|
|
16423
|
+
if (timeInfoInET.hour < expectedHour) {
|
|
16424
|
+
return 1;
|
|
16425
|
+
}
|
|
16426
|
+
if (timeInfoInET.hour > expectedHour) {
|
|
16427
|
+
return -1;
|
|
16428
|
+
}
|
|
16429
|
+
if (timeInfoInET.minute < expectedMinute) {
|
|
16430
|
+
return 1;
|
|
16431
|
+
}
|
|
16432
|
+
if (timeInfoInET.minute > expectedMinute) {
|
|
16433
|
+
return -1;
|
|
16434
|
+
}
|
|
16435
|
+
return 0;
|
|
16436
|
+
};
|
|
16437
|
+
/*----------------------------------------*/
|
|
16438
|
+
/* ---------------- Main ---------------- */
|
|
16439
|
+
/*----------------------------------------*/
|
|
16388
16440
|
/**
|
|
16389
16441
|
* Get a timestamp (ms since epoch) from time info (year, month, day, hour, minute, etc.) in Eastern Time (ET)
|
|
16390
16442
|
* @author Gardenia Liu
|
|
@@ -16394,79 +16446,64 @@ const getWordCount = (text) => {
|
|
|
16394
16446
|
* @param opts.month Month (1-12)
|
|
16395
16447
|
* @param opts.day Day of the month (1-31)
|
|
16396
16448
|
* @param opts.hour Hour (0-23)
|
|
16397
|
-
* @param opts.minute Minute (0-59)
|
|
16449
|
+
* @param opts.minute Minute (0-59)
|
|
16398
16450
|
* @returns Timestamp in milliseconds since epoch
|
|
16399
16451
|
*/
|
|
16400
16452
|
const getTimestampFromTimeInfoInET = (opts) => {
|
|
16401
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
16402
16453
|
// Destructure opts
|
|
16403
16454
|
const { year, month, day, hour, minute, } = opts;
|
|
16455
|
+
// Determine if the date is in DST in Eastern Time
|
|
16456
|
+
const tempDate = new Date(year, month - 1, day);
|
|
16457
|
+
const janOffset = new Date(year, 0, 1).getTimezoneOffset();
|
|
16458
|
+
const isDST = tempDate.getTimezoneOffset() < janOffset;
|
|
16459
|
+
const etOffset = isDST ? '-04:00' : '-05:00';
|
|
16404
16460
|
// Format with leading zeroes
|
|
16405
16461
|
const mm = padZerosLeft(month, 2);
|
|
16406
16462
|
const dd = padZerosLeft(day, 2);
|
|
16407
16463
|
const hh = padZerosLeft(hour, 2);
|
|
16408
16464
|
const min = padZerosLeft(minute, 2);
|
|
16409
|
-
//
|
|
16410
|
-
const
|
|
16411
|
-
|
|
16412
|
-
|
|
16413
|
-
|
|
16414
|
-
|
|
16415
|
-
|
|
16416
|
-
|
|
16417
|
-
|
|
16418
|
-
|
|
16419
|
-
|
|
16420
|
-
|
|
16421
|
-
|
|
16422
|
-
|
|
16423
|
-
|
|
16424
|
-
|
|
16425
|
-
|
|
16426
|
-
|
|
16427
|
-
|
|
16428
|
-
|
|
16429
|
-
|
|
16430
|
-
|
|
16431
|
-
|
|
16432
|
-
|
|
16433
|
-
|
|
16434
|
-
|
|
16435
|
-
|
|
16436
|
-
|
|
16437
|
-
|
|
16438
|
-
|
|
16439
|
-
|
|
16440
|
-
|
|
16441
|
-
|
|
16442
|
-
|
|
16443
|
-
|
|
16444
|
-
|
|
16445
|
-
|
|
16446
|
-
|
|
16447
|
-
|
|
16448
|
-
|
|
16449
|
-
|
|
16450
|
-
|
|
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();
|
|
16457
|
-
// Verify that the timestamp is correct
|
|
16458
|
-
const timeInfoInET = getTimeInfoInET(timestamp);
|
|
16459
|
-
if (timeInfoInET.year !== year
|
|
16460
|
-
|| timeInfoInET.month !== month
|
|
16461
|
-
|| timeInfoInET.day !== day
|
|
16462
|
-
|| timeInfoInET.hour !== hour
|
|
16463
|
-
|| timeInfoInET.minute !== minute) {
|
|
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);
|
|
16467
|
-
}
|
|
16468
|
-
// Valid! Return the timestamp
|
|
16469
|
-
return timestamp;
|
|
16465
|
+
// Build ET ISO string and convert to UTC timestamp
|
|
16466
|
+
const etISOString = `${year}-${mm}-${dd}T${hh}:${min}:00${etOffset}`;
|
|
16467
|
+
let timestamp = (new Date(etISOString)).getTime();
|
|
16468
|
+
// Heat seek to get the right timestamp
|
|
16469
|
+
const maxOffset = 24 * 60; // 24 hours in minutes
|
|
16470
|
+
let currentOffset = 0; // minutes
|
|
16471
|
+
const offsetIncrement = 15; // minutes
|
|
16472
|
+
const offsetDirection = checkTimestamp({
|
|
16473
|
+
timestamp,
|
|
16474
|
+
expectedYear: year,
|
|
16475
|
+
expectedMonth: month,
|
|
16476
|
+
expectedDay: day,
|
|
16477
|
+
expectedHour: hour,
|
|
16478
|
+
expectedMinute: minute,
|
|
16479
|
+
});
|
|
16480
|
+
if (offsetDirection === 0) {
|
|
16481
|
+
// Valid! Return the timestamp
|
|
16482
|
+
return timestamp;
|
|
16483
|
+
}
|
|
16484
|
+
// Heat seek
|
|
16485
|
+
while (Math.abs(currentOffset) < maxOffset) {
|
|
16486
|
+
// Update offset
|
|
16487
|
+
currentOffset += (offsetDirection * offsetIncrement);
|
|
16488
|
+
// Update timestamp
|
|
16489
|
+
const offsetMs = currentOffset * 60 * 1000;
|
|
16490
|
+
timestamp += offsetMs;
|
|
16491
|
+
// Check timestamp again
|
|
16492
|
+
const newDirection = checkTimestamp({
|
|
16493
|
+
timestamp,
|
|
16494
|
+
expectedYear: year,
|
|
16495
|
+
expectedMonth: month,
|
|
16496
|
+
expectedDay: day,
|
|
16497
|
+
expectedHour: hour,
|
|
16498
|
+
expectedMinute: minute,
|
|
16499
|
+
});
|
|
16500
|
+
if (newDirection === 0) {
|
|
16501
|
+
// Valid! Return the timestamp
|
|
16502
|
+
return timestamp;
|
|
16503
|
+
}
|
|
16504
|
+
// Invalid. Keep looping.
|
|
16505
|
+
}
|
|
16506
|
+
throw new ErrorWithCode(`Timestamp mismatch: expected ${year}-${mm}-${dd} ${hh}:${min}, seeked to offset ${currentOffset} minutes but could not find a valid timestamp.`, ReactKitErrorCode$1.ETTimestampInvalid);
|
|
16470
16507
|
};
|
|
16471
16508
|
|
|
16472
16509
|
/*------------------------------------------------------------------------*/
|