dce-reactkit 4.2.6 → 4.2.7

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.
@@ -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,46 @@ 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 timestamp = (new Date(etISOString)).getTime();
16612
- // Verify that the timestamp is correct
16613
- const timeInfoInET = getTimeInfoInET(timestamp);
16614
- if (timeInfoInET.year !== year
16615
- || timeInfoInET.month !== month
16616
- || timeInfoInET.day !== day
16617
- || timeInfoInET.hour !== hour
16618
- || timeInfoInET.minute !== minute) {
16619
- 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);
16620
- }
16621
- // Valid! Return the timestamp
16622
- return timestamp;
16665
+ let timestamp = (new Date(etISOString)).getTime();
16666
+ // Heat seek to get the right timestamp
16667
+ const maxOffset = 24 * 60; // 24 hours in minutes
16668
+ let currentOffset = 0; // minutes
16669
+ const offsetIncrement = 15; // minutes
16670
+ const offsetDirection = checkTimestamp({
16671
+ timestamp,
16672
+ expectedYear: year,
16673
+ expectedMonth: month,
16674
+ expectedDay: day,
16675
+ expectedHour: hour,
16676
+ expectedMinute: minute,
16677
+ });
16678
+ if (offsetDirection === 0) {
16679
+ // Valid! Return the timestamp
16680
+ return timestamp;
16681
+ }
16682
+ // Heat seek
16683
+ while (Math.abs(currentOffset) < maxOffset) {
16684
+ // Update offset
16685
+ currentOffset += (offsetDirection * offsetIncrement);
16686
+ // Update timestamp
16687
+ const offsetMs = currentOffset * 60 * 1000;
16688
+ timestamp += offsetMs;
16689
+ // Check timestamp again
16690
+ const newDirection = checkTimestamp({
16691
+ timestamp,
16692
+ expectedYear: year,
16693
+ expectedMonth: month,
16694
+ expectedDay: day,
16695
+ expectedHour: hour,
16696
+ expectedMinute: minute,
16697
+ });
16698
+ if (newDirection === 0) {
16699
+ // Valid! Return the timestamp
16700
+ return timestamp;
16701
+ }
16702
+ // Invalid. Keep looping.
16703
+ }
16704
+ 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
16705
  };
16624
16706
 
16625
16707
  /*------------------------------------------------------------------------*/