@capillarytech/blaze-ui 5.1.18 → 5.1.20

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.
@@ -485,6 +485,7 @@ exports.isDayjsObject = isDayjsObject;
485
485
  exports.isMomentObject = isMomentObject;
486
486
  exports.momentToDayjs = momentToDayjs;
487
487
  exports.normalizeDateValue = normalizeDateValue;
488
+ exports.toDayjsInTimezone = toDayjsInTimezone;
488
489
  var _dayjs = _interopRequireDefault(__webpack_require__(87695));
489
490
  var _advancedFormat = _interopRequireDefault(__webpack_require__(96833));
490
491
  var _customParseFormat = _interopRequireDefault(__webpack_require__(2825));
@@ -596,7 +597,23 @@ if (!tzIsCallable) {
596
597
  if (_dayjs.default.isDayjs(date)) {
597
598
  return date.tz(tzName);
598
599
  }
599
- return (0, _dayjs.default)(date).tz(tzName);
600
+ // For strings/Dates: interpret the date/time values as being IN the target timezone
601
+ // (matching moment.tz(string, tz) semantics). dayjs(date).tz(tz) is wrong because
602
+ // dayjs(date) anchors to the system local timezone, so .tz() converts FROM local TO tz.
603
+ // Instead: parse as UTC to get raw date/time values, compute the target timezone's offset,
604
+ // then adjust the UTC timestamp so .tz() produces the intended local time.
605
+ try {
606
+ // Validate timezone is a real IANA timezone before applying the offset correction
607
+ Intl.DateTimeFormat(undefined, {
608
+ timeZone: tzName
609
+ });
610
+ } catch (_unused) {
611
+ // Invalid timezone — fall back to local time
612
+ return (0, _dayjs.default)(date);
613
+ }
614
+ const asUtc = _dayjs.default.utc(date);
615
+ const tzOffset = asUtc.tz(tzName).utcOffset(); // target tz offset in minutes
616
+ return _dayjs.default.utc(asUtc.valueOf() - tzOffset * 60000).tz(tzName);
600
617
  } catch (error) {
601
618
  // If timezone is invalid, log error and fall back to local time
602
619
  logDevError("dayjs.tz: Invalid timezone \"" + tzName + "\"", error);
@@ -766,7 +783,10 @@ function momentToDayjs(value) {
766
783
  const tz = value.tz();
767
784
  if (tz) {
768
785
  // Has a named timezone - preserve it
769
- dayjsObj = (0, _dayjs.default)(date).tz(tz);
786
+ // dayjs.utc(date) is required here: dayjs(date) anchors to the system local timezone,
787
+ // causing .tz() to only re-label without converting hours. dayjs.utc(date) creates a
788
+ // UTC-mode dayjs, which .tz() correctly converts to the target timezone for display.
789
+ dayjsObj = _dayjs.default.utc(date).tz(tz);
770
790
 
771
791
  // WORKAROUND: dayjs-timezone-iana-plugin doesn't persist timezone name in standard way
772
792
  // Store it manually in $x for round-trip conversion fidelity
@@ -819,6 +839,35 @@ function momentToDayjs(value) {
819
839
  return null;
820
840
  }
821
841
 
842
+ /**
843
+ * Converts any supported date value (Moment, Day.js, string, Date) to a Day.js object
844
+ * in the specified timezone. This is the recommended single entry point for timezone-safe
845
+ * date conversion — it handles moment-to-dayjs conversion and timezone application in one step,
846
+ * avoiding the double-offset bug in dayjs-timezone-iana-plugin.
847
+ *
848
+ * @param value - Moment, Day.js, string, Date, or null/undefined
849
+ * @param timezone - Target IANA timezone (e.g., 'Asia/Kolkata', 'America/New_York')
850
+ * @returns Day.js object in the target timezone, or null if invalid
851
+ *
852
+ * @example
853
+ * toDayjsInTimezone(moment.tz('2025-04-21 00:00', 'Asia/Kolkata'), 'Asia/Kolkata');
854
+ * // Returns dayjs representing 2025-04-21 00:00 IST
855
+ *
856
+ * @example
857
+ * toDayjsInTimezone(moment.tz('2025-04-21 00:00', 'UTC'), 'Asia/Kolkata');
858
+ * // Returns dayjs representing 2025-04-21 05:30 IST
859
+ */
860
+ function toDayjsInTimezone(value, timezone) {
861
+ const dayjsValue = momentToDayjs(value);
862
+ if (!dayjsValue) return null;
863
+
864
+ // Convert via UTC to avoid the double-offset bug in dayjs-timezone-iana-plugin:
865
+ // calling .tz() on a dayjs that already has a non-zero utcOffset corrupts the value.
866
+ // Going through .toDate() → dayjs.utc() gives us a clean UTC-mode dayjs that .tz()
867
+ // correctly converts to the target timezone.
868
+ return _dayjs.default.utc(dayjsValue.toDate()).tz(timezone);
869
+ }
870
+
822
871
  /**
823
872
  * Converts a Day.js object to Moment.js, preserving timezone and locale information.
824
873
  *