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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @param opts.month Month (1-12)
|
|
8
8
|
* @param opts.day Day of the month (1-31)
|
|
9
9
|
* @param opts.hour Hour (0-23)
|
|
10
|
-
* @param opts.minute Minute (0-59)
|
|
10
|
+
* @param opts.minute Minute (0-59)
|
|
11
11
|
* @returns Timestamp in milliseconds since epoch
|
|
12
12
|
*/
|
|
13
13
|
declare const getTimestampFromTimeInfoInET: (opts: {
|
package/dist/esm/index.js
CHANGED
|
@@ -16358,6 +16358,58 @@ const getWordCount = (text) => {
|
|
|
16358
16358
|
};
|
|
16359
16359
|
|
|
16360
16360
|
// Import shared types
|
|
16361
|
+
/*----------------------------------------*/
|
|
16362
|
+
/* --------------- Helpers -------------- */
|
|
16363
|
+
/*----------------------------------------*/
|
|
16364
|
+
/**
|
|
16365
|
+
* Check if a timestamp is valid
|
|
16366
|
+
* @param opts object containing all arguments
|
|
16367
|
+
* @param opts.timestamp Timestamp in milliseconds since epoch
|
|
16368
|
+
* @param opts.expectedYear Expected year
|
|
16369
|
+
* @param opts.expectedMonth Expected month
|
|
16370
|
+
* @param opts.expectedDay Expected day
|
|
16371
|
+
* @param opts.expectedHour Expected hour
|
|
16372
|
+
* @param opts.expectedMinute Expected minute
|
|
16373
|
+
* @returns 1 if the timestamp needs to be increased, -1 if it needs to be decreased, 0 if it is valid
|
|
16374
|
+
*/
|
|
16375
|
+
const checkTimestamp = (opts) => {
|
|
16376
|
+
const { timestamp, expectedYear, expectedMonth, expectedDay, expectedHour, expectedMinute, } = opts;
|
|
16377
|
+
const timeInfoInET = getTimeInfoInET(timestamp);
|
|
16378
|
+
if (timeInfoInET.year < expectedYear) {
|
|
16379
|
+
return 1;
|
|
16380
|
+
}
|
|
16381
|
+
if (timeInfoInET.year > expectedYear) {
|
|
16382
|
+
return -1;
|
|
16383
|
+
}
|
|
16384
|
+
if (timeInfoInET.month < expectedMonth) {
|
|
16385
|
+
return 1;
|
|
16386
|
+
}
|
|
16387
|
+
if (timeInfoInET.month > expectedMonth) {
|
|
16388
|
+
return -1;
|
|
16389
|
+
}
|
|
16390
|
+
if (timeInfoInET.day < expectedDay) {
|
|
16391
|
+
return 1;
|
|
16392
|
+
}
|
|
16393
|
+
if (timeInfoInET.day > expectedDay) {
|
|
16394
|
+
return -1;
|
|
16395
|
+
}
|
|
16396
|
+
if (timeInfoInET.hour < expectedHour) {
|
|
16397
|
+
return 1;
|
|
16398
|
+
}
|
|
16399
|
+
if (timeInfoInET.hour > expectedHour) {
|
|
16400
|
+
return -1;
|
|
16401
|
+
}
|
|
16402
|
+
if (timeInfoInET.minute < expectedMinute) {
|
|
16403
|
+
return 1;
|
|
16404
|
+
}
|
|
16405
|
+
if (timeInfoInET.minute > expectedMinute) {
|
|
16406
|
+
return -1;
|
|
16407
|
+
}
|
|
16408
|
+
return 0;
|
|
16409
|
+
};
|
|
16410
|
+
/*----------------------------------------*/
|
|
16411
|
+
/* ---------------- Main ---------------- */
|
|
16412
|
+
/*----------------------------------------*/
|
|
16361
16413
|
/**
|
|
16362
16414
|
* Get a timestamp (ms since epoch) from time info (year, month, day, hour, minute, etc.) in Eastern Time (ET)
|
|
16363
16415
|
* @author Gardenia Liu
|
|
@@ -16367,79 +16419,64 @@ const getWordCount = (text) => {
|
|
|
16367
16419
|
* @param opts.month Month (1-12)
|
|
16368
16420
|
* @param opts.day Day of the month (1-31)
|
|
16369
16421
|
* @param opts.hour Hour (0-23)
|
|
16370
|
-
* @param opts.minute Minute (0-59)
|
|
16422
|
+
* @param opts.minute Minute (0-59)
|
|
16371
16423
|
* @returns Timestamp in milliseconds since epoch
|
|
16372
16424
|
*/
|
|
16373
16425
|
const getTimestampFromTimeInfoInET = (opts) => {
|
|
16374
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
16375
16426
|
// Destructure opts
|
|
16376
16427
|
const { year, month, day, hour, minute, } = opts;
|
|
16428
|
+
// Determine if the date is in DST in Eastern Time
|
|
16429
|
+
const tempDate = new Date(year, month - 1, day);
|
|
16430
|
+
const janOffset = new Date(year, 0, 1).getTimezoneOffset();
|
|
16431
|
+
const isDST = tempDate.getTimezoneOffset() < janOffset;
|
|
16432
|
+
const etOffset = isDST ? '-04:00' : '-05:00';
|
|
16377
16433
|
// Format with leading zeroes
|
|
16378
16434
|
const mm = padZerosLeft(month, 2);
|
|
16379
16435
|
const dd = padZerosLeft(day, 2);
|
|
16380
16436
|
const hh = padZerosLeft(hour, 2);
|
|
16381
16437
|
const min = padZerosLeft(minute, 2);
|
|
16382
|
-
//
|
|
16383
|
-
const
|
|
16384
|
-
|
|
16385
|
-
|
|
16386
|
-
|
|
16387
|
-
|
|
16388
|
-
|
|
16389
|
-
|
|
16390
|
-
|
|
16391
|
-
|
|
16392
|
-
|
|
16393
|
-
|
|
16394
|
-
|
|
16395
|
-
|
|
16396
|
-
|
|
16397
|
-
|
|
16398
|
-
|
|
16399
|
-
|
|
16400
|
-
|
|
16401
|
-
|
|
16402
|
-
|
|
16403
|
-
|
|
16404
|
-
|
|
16405
|
-
|
|
16406
|
-
|
|
16407
|
-
|
|
16408
|
-
|
|
16409
|
-
|
|
16410
|
-
|
|
16411
|
-
|
|
16412
|
-
|
|
16413
|
-
|
|
16414
|
-
|
|
16415
|
-
|
|
16416
|
-
|
|
16417
|
-
|
|
16418
|
-
|
|
16419
|
-
|
|
16420
|
-
|
|
16421
|
-
|
|
16422
|
-
|
|
16423
|
-
|
|
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();
|
|
16430
|
-
// Verify that the timestamp is correct
|
|
16431
|
-
const timeInfoInET = getTimeInfoInET(timestamp);
|
|
16432
|
-
if (timeInfoInET.year !== year
|
|
16433
|
-
|| timeInfoInET.month !== month
|
|
16434
|
-
|| timeInfoInET.day !== day
|
|
16435
|
-
|| timeInfoInET.hour !== hour
|
|
16436
|
-
|| timeInfoInET.minute !== minute) {
|
|
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);
|
|
16440
|
-
}
|
|
16441
|
-
// Valid! Return the timestamp
|
|
16442
|
-
return timestamp;
|
|
16438
|
+
// Build ET ISO string and convert to UTC timestamp
|
|
16439
|
+
const etISOString = `${year}-${mm}-${dd}T${hh}:${min}:00${etOffset}`;
|
|
16440
|
+
let timestamp = (new Date(etISOString)).getTime();
|
|
16441
|
+
// Heat seek to get the right timestamp
|
|
16442
|
+
const maxOffset = 24 * 60; // 24 hours in minutes
|
|
16443
|
+
let currentOffset = 0; // minutes
|
|
16444
|
+
const offsetIncrement = 15; // minutes
|
|
16445
|
+
const offsetDirection = checkTimestamp({
|
|
16446
|
+
timestamp,
|
|
16447
|
+
expectedYear: year,
|
|
16448
|
+
expectedMonth: month,
|
|
16449
|
+
expectedDay: day,
|
|
16450
|
+
expectedHour: hour,
|
|
16451
|
+
expectedMinute: minute,
|
|
16452
|
+
});
|
|
16453
|
+
if (offsetDirection === 0) {
|
|
16454
|
+
// Valid! Return the timestamp
|
|
16455
|
+
return timestamp;
|
|
16456
|
+
}
|
|
16457
|
+
// Heat seek
|
|
16458
|
+
while (Math.abs(currentOffset) < maxOffset) {
|
|
16459
|
+
// Update offset
|
|
16460
|
+
currentOffset += (offsetDirection * offsetIncrement);
|
|
16461
|
+
// Update timestamp
|
|
16462
|
+
const offsetMs = currentOffset * 60 * 1000;
|
|
16463
|
+
timestamp += offsetMs;
|
|
16464
|
+
// Check timestamp again
|
|
16465
|
+
const newDirection = checkTimestamp({
|
|
16466
|
+
timestamp,
|
|
16467
|
+
expectedYear: year,
|
|
16468
|
+
expectedMonth: month,
|
|
16469
|
+
expectedDay: day,
|
|
16470
|
+
expectedHour: hour,
|
|
16471
|
+
expectedMinute: minute,
|
|
16472
|
+
});
|
|
16473
|
+
if (newDirection === 0) {
|
|
16474
|
+
// Valid! Return the timestamp
|
|
16475
|
+
return timestamp;
|
|
16476
|
+
}
|
|
16477
|
+
// Invalid. Keep looping.
|
|
16478
|
+
}
|
|
16479
|
+
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);
|
|
16443
16480
|
};
|
|
16444
16481
|
|
|
16445
16482
|
/*------------------------------------------------------------------------*/
|