dce-reactkit 4.2.6 → 4.2.8-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 +96 -13
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/helpers/getTimestampFromTimeInfoInET.d.ts +1 -1
- package/dist/esm/index.js +96 -13
- 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 +122 -17
|
@@ -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
|
@@ -16581,6 +16581,60 @@ const getWordCount = (text) => {
|
|
|
16581
16581
|
};
|
|
16582
16582
|
|
|
16583
16583
|
// Import shared types
|
|
16584
|
+
/*----------------------------------------*/
|
|
16585
|
+
/* --------------- Helpers -------------- */
|
|
16586
|
+
/*----------------------------------------*/
|
|
16587
|
+
/**
|
|
16588
|
+
* Check if a timestamp is valid
|
|
16589
|
+
* @author Gabe Abrams
|
|
16590
|
+
* @author Gardenia Liu
|
|
16591
|
+
* @param opts object containing all arguments
|
|
16592
|
+
* @param opts.timestamp Timestamp in milliseconds since epoch
|
|
16593
|
+
* @param opts.expectedYear Expected year
|
|
16594
|
+
* @param opts.expectedMonth Expected month
|
|
16595
|
+
* @param opts.expectedDay Expected day
|
|
16596
|
+
* @param opts.expectedHour Expected hour
|
|
16597
|
+
* @param opts.expectedMinute Expected minute
|
|
16598
|
+
* @returns 1 if the timestamp needs to be increased, -1 if it needs to be decreased, 0 if it is valid
|
|
16599
|
+
*/
|
|
16600
|
+
const checkTimestamp = (opts) => {
|
|
16601
|
+
const { timestamp, expectedYear, expectedMonth, expectedDay, expectedHour, expectedMinute, } = opts;
|
|
16602
|
+
const timeInfoInET = getTimeInfoInET(timestamp);
|
|
16603
|
+
if (timeInfoInET.year < expectedYear) {
|
|
16604
|
+
return 1;
|
|
16605
|
+
}
|
|
16606
|
+
if (timeInfoInET.year > expectedYear) {
|
|
16607
|
+
return -1;
|
|
16608
|
+
}
|
|
16609
|
+
if (timeInfoInET.month < expectedMonth) {
|
|
16610
|
+
return 1;
|
|
16611
|
+
}
|
|
16612
|
+
if (timeInfoInET.month > expectedMonth) {
|
|
16613
|
+
return -1;
|
|
16614
|
+
}
|
|
16615
|
+
if (timeInfoInET.day < expectedDay) {
|
|
16616
|
+
return 1;
|
|
16617
|
+
}
|
|
16618
|
+
if (timeInfoInET.day > expectedDay) {
|
|
16619
|
+
return -1;
|
|
16620
|
+
}
|
|
16621
|
+
if (timeInfoInET.hour < expectedHour) {
|
|
16622
|
+
return 1;
|
|
16623
|
+
}
|
|
16624
|
+
if (timeInfoInET.hour > expectedHour) {
|
|
16625
|
+
return -1;
|
|
16626
|
+
}
|
|
16627
|
+
if (timeInfoInET.minute < expectedMinute) {
|
|
16628
|
+
return 1;
|
|
16629
|
+
}
|
|
16630
|
+
if (timeInfoInET.minute > expectedMinute) {
|
|
16631
|
+
return -1;
|
|
16632
|
+
}
|
|
16633
|
+
return 0;
|
|
16634
|
+
};
|
|
16635
|
+
/*----------------------------------------*/
|
|
16636
|
+
/* ---------------- Main ---------------- */
|
|
16637
|
+
/*----------------------------------------*/
|
|
16584
16638
|
/**
|
|
16585
16639
|
* Get a timestamp (ms since epoch) from time info (year, month, day, hour, minute, etc.) in Eastern Time (ET)
|
|
16586
16640
|
* @author Gardenia Liu
|
|
@@ -16590,7 +16644,7 @@ const getWordCount = (text) => {
|
|
|
16590
16644
|
* @param opts.month Month (1-12)
|
|
16591
16645
|
* @param opts.day Day of the month (1-31)
|
|
16592
16646
|
* @param opts.hour Hour (0-23)
|
|
16593
|
-
* @param opts.minute Minute (0-59)
|
|
16647
|
+
* @param opts.minute Minute (0-59)
|
|
16594
16648
|
* @returns Timestamp in milliseconds since epoch
|
|
16595
16649
|
*/
|
|
16596
16650
|
const getTimestampFromTimeInfoInET = (opts) => {
|
|
@@ -16608,18 +16662,47 @@ const getTimestampFromTimeInfoInET = (opts) => {
|
|
|
16608
16662
|
const min = padZerosLeft(minute, 2);
|
|
16609
16663
|
// Build ET ISO string and convert to UTC timestamp
|
|
16610
16664
|
const etISOString = `${year}-${mm}-${dd}T${hh}:${min}:00${etOffset}`;
|
|
16611
|
-
const
|
|
16612
|
-
|
|
16613
|
-
|
|
16614
|
-
|
|
16615
|
-
|
|
16616
|
-
|
|
16617
|
-
|
|
16618
|
-
|
|
16619
|
-
|
|
16620
|
-
|
|
16621
|
-
|
|
16622
|
-
|
|
16665
|
+
const baseTimestamp = (new Date(etISOString)).getTime();
|
|
16666
|
+
let timestamp = baseTimestamp;
|
|
16667
|
+
// Heat seek to get the right timestamp
|
|
16668
|
+
const maxOffset = 24 * 60; // 24 hours in minutes
|
|
16669
|
+
let currentOffset = 0; // minutes
|
|
16670
|
+
const offsetIncrement = 15; // minutes
|
|
16671
|
+
const offsetDirection = checkTimestamp({
|
|
16672
|
+
timestamp,
|
|
16673
|
+
expectedYear: year,
|
|
16674
|
+
expectedMonth: month,
|
|
16675
|
+
expectedDay: day,
|
|
16676
|
+
expectedHour: hour,
|
|
16677
|
+
expectedMinute: minute,
|
|
16678
|
+
});
|
|
16679
|
+
if (offsetDirection === 0) {
|
|
16680
|
+
// Valid! Return the timestamp
|
|
16681
|
+
return timestamp;
|
|
16682
|
+
}
|
|
16683
|
+
// Heat seek
|
|
16684
|
+
while (Math.abs(currentOffset) < maxOffset) {
|
|
16685
|
+
// Update offset
|
|
16686
|
+
currentOffset += (offsetDirection * offsetIncrement);
|
|
16687
|
+
// Update timestamp
|
|
16688
|
+
const offsetMs = currentOffset * 60 * 1000;
|
|
16689
|
+
timestamp = baseTimestamp + offsetMs;
|
|
16690
|
+
// Check timestamp again
|
|
16691
|
+
const newDirection = checkTimestamp({
|
|
16692
|
+
timestamp,
|
|
16693
|
+
expectedYear: year,
|
|
16694
|
+
expectedMonth: month,
|
|
16695
|
+
expectedDay: day,
|
|
16696
|
+
expectedHour: hour,
|
|
16697
|
+
expectedMinute: minute,
|
|
16698
|
+
});
|
|
16699
|
+
if (newDirection === 0) {
|
|
16700
|
+
// Valid! Return the timestamp
|
|
16701
|
+
return timestamp;
|
|
16702
|
+
}
|
|
16703
|
+
// Invalid. Keep looping.
|
|
16704
|
+
}
|
|
16705
|
+
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);
|
|
16623
16706
|
};
|
|
16624
16707
|
|
|
16625
16708
|
/*------------------------------------------------------------------------*/
|