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.
package/dist/cjs/index.js CHANGED
@@ -16608,6 +16608,60 @@ const getWordCount = (text) => {
16608
16608
  };
16609
16609
 
16610
16610
  // Import shared types
16611
+ /*----------------------------------------*/
16612
+ /* --------------- Helpers -------------- */
16613
+ /*----------------------------------------*/
16614
+ /**
16615
+ * Check if a timestamp is valid
16616
+ * @author Gabe Abrams
16617
+ * @author Gardenia Liu
16618
+ * @param opts object containing all arguments
16619
+ * @param opts.timestamp Timestamp in milliseconds since epoch
16620
+ * @param opts.expectedYear Expected year
16621
+ * @param opts.expectedMonth Expected month
16622
+ * @param opts.expectedDay Expected day
16623
+ * @param opts.expectedHour Expected hour
16624
+ * @param opts.expectedMinute Expected minute
16625
+ * @returns 1 if the timestamp needs to be increased, -1 if it needs to be decreased, 0 if it is valid
16626
+ */
16627
+ const checkTimestamp = (opts) => {
16628
+ const { timestamp, expectedYear, expectedMonth, expectedDay, expectedHour, expectedMinute, } = opts;
16629
+ const timeInfoInET = getTimeInfoInET(timestamp);
16630
+ if (timeInfoInET.year < expectedYear) {
16631
+ return 1;
16632
+ }
16633
+ if (timeInfoInET.year > expectedYear) {
16634
+ return -1;
16635
+ }
16636
+ if (timeInfoInET.month < expectedMonth) {
16637
+ return 1;
16638
+ }
16639
+ if (timeInfoInET.month > expectedMonth) {
16640
+ return -1;
16641
+ }
16642
+ if (timeInfoInET.day < expectedDay) {
16643
+ return 1;
16644
+ }
16645
+ if (timeInfoInET.day > expectedDay) {
16646
+ return -1;
16647
+ }
16648
+ if (timeInfoInET.hour < expectedHour) {
16649
+ return 1;
16650
+ }
16651
+ if (timeInfoInET.hour > expectedHour) {
16652
+ return -1;
16653
+ }
16654
+ if (timeInfoInET.minute < expectedMinute) {
16655
+ return 1;
16656
+ }
16657
+ if (timeInfoInET.minute > expectedMinute) {
16658
+ return -1;
16659
+ }
16660
+ return 0;
16661
+ };
16662
+ /*----------------------------------------*/
16663
+ /* ---------------- Main ---------------- */
16664
+ /*----------------------------------------*/
16611
16665
  /**
16612
16666
  * Get a timestamp (ms since epoch) from time info (year, month, day, hour, minute, etc.) in Eastern Time (ET)
16613
16667
  * @author Gardenia Liu
@@ -16617,7 +16671,7 @@ const getWordCount = (text) => {
16617
16671
  * @param opts.month Month (1-12)
16618
16672
  * @param opts.day Day of the month (1-31)
16619
16673
  * @param opts.hour Hour (0-23)
16620
- * @param opts.minute Minute (0-59))
16674
+ * @param opts.minute Minute (0-59)
16621
16675
  * @returns Timestamp in milliseconds since epoch
16622
16676
  */
16623
16677
  const getTimestampFromTimeInfoInET = (opts) => {
@@ -16635,18 +16689,46 @@ const getTimestampFromTimeInfoInET = (opts) => {
16635
16689
  const min = padZerosLeft(minute, 2);
16636
16690
  // Build ET ISO string and convert to UTC timestamp
16637
16691
  const etISOString = `${year}-${mm}-${dd}T${hh}:${min}:00${etOffset}`;
16638
- const timestamp = (new Date(etISOString)).getTime();
16639
- // Verify that the timestamp is correct
16640
- const timeInfoInET = getTimeInfoInET(timestamp);
16641
- if (timeInfoInET.year !== year
16642
- || timeInfoInET.month !== month
16643
- || timeInfoInET.day !== day
16644
- || timeInfoInET.hour !== hour
16645
- || timeInfoInET.minute !== minute) {
16646
- 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);
16647
- }
16648
- // Valid! Return the timestamp
16649
- return timestamp;
16692
+ let timestamp = (new Date(etISOString)).getTime();
16693
+ // Heat seek to get the right timestamp
16694
+ const maxOffset = 24 * 60; // 24 hours in minutes
16695
+ let currentOffset = 0; // minutes
16696
+ const offsetIncrement = 15; // minutes
16697
+ const offsetDirection = checkTimestamp({
16698
+ timestamp,
16699
+ expectedYear: year,
16700
+ expectedMonth: month,
16701
+ expectedDay: day,
16702
+ expectedHour: hour,
16703
+ expectedMinute: minute,
16704
+ });
16705
+ if (offsetDirection === 0) {
16706
+ // Valid! Return the timestamp
16707
+ return timestamp;
16708
+ }
16709
+ // Heat seek
16710
+ while (Math.abs(currentOffset) < maxOffset) {
16711
+ // Update offset
16712
+ currentOffset += (offsetDirection * offsetIncrement);
16713
+ // Update timestamp
16714
+ const offsetMs = currentOffset * 60 * 1000;
16715
+ timestamp += offsetMs;
16716
+ // Check timestamp again
16717
+ const newDirection = checkTimestamp({
16718
+ timestamp,
16719
+ expectedYear: year,
16720
+ expectedMonth: month,
16721
+ expectedDay: day,
16722
+ expectedHour: hour,
16723
+ expectedMinute: minute,
16724
+ });
16725
+ if (newDirection === 0) {
16726
+ // Valid! Return the timestamp
16727
+ return timestamp;
16728
+ }
16729
+ // Invalid. Keep looping.
16730
+ }
16731
+ 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);
16650
16732
  };
16651
16733
 
16652
16734
  /*------------------------------------------------------------------------*/