@capillarytech/blaze-ui 5.1.19 → 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.
@@ -4444,6 +4444,7 @@ exports.isDayjsObject = isDayjsObject;
4444
4444
  exports.isMomentObject = isMomentObject;
4445
4445
  exports.momentToDayjs = momentToDayjs;
4446
4446
  exports.normalizeDateValue = normalizeDateValue;
4447
+ exports.toDayjsInTimezone = toDayjsInTimezone;
4447
4448
  var _dayjs = _interopRequireDefault(__webpack_require__(87695));
4448
4449
  var _advancedFormat = _interopRequireDefault(__webpack_require__(96833));
4449
4450
  var _customParseFormat = _interopRequireDefault(__webpack_require__(2825));
@@ -4555,7 +4556,23 @@ if (!tzIsCallable) {
4555
4556
  if (_dayjs.default.isDayjs(date)) {
4556
4557
  return date.tz(tzName);
4557
4558
  }
4558
- return (0, _dayjs.default)(date).tz(tzName);
4559
+ // For strings/Dates: interpret the date/time values as being IN the target timezone
4560
+ // (matching moment.tz(string, tz) semantics). dayjs(date).tz(tz) is wrong because
4561
+ // dayjs(date) anchors to the system local timezone, so .tz() converts FROM local TO tz.
4562
+ // Instead: parse as UTC to get raw date/time values, compute the target timezone's offset,
4563
+ // then adjust the UTC timestamp so .tz() produces the intended local time.
4564
+ try {
4565
+ // Validate timezone is a real IANA timezone before applying the offset correction
4566
+ Intl.DateTimeFormat(undefined, {
4567
+ timeZone: tzName
4568
+ });
4569
+ } catch (_unused) {
4570
+ // Invalid timezone — fall back to local time
4571
+ return (0, _dayjs.default)(date);
4572
+ }
4573
+ const asUtc = _dayjs.default.utc(date);
4574
+ const tzOffset = asUtc.tz(tzName).utcOffset(); // target tz offset in minutes
4575
+ return _dayjs.default.utc(asUtc.valueOf() - tzOffset * 60000).tz(tzName);
4559
4576
  } catch (error) {
4560
4577
  // If timezone is invalid, log error and fall back to local time
4561
4578
  logDevError("dayjs.tz: Invalid timezone \"" + tzName + "\"", error);
@@ -4781,6 +4798,35 @@ function momentToDayjs(value) {
4781
4798
  return null;
4782
4799
  }
4783
4800
 
4801
+ /**
4802
+ * Converts any supported date value (Moment, Day.js, string, Date) to a Day.js object
4803
+ * in the specified timezone. This is the recommended single entry point for timezone-safe
4804
+ * date conversion — it handles moment-to-dayjs conversion and timezone application in one step,
4805
+ * avoiding the double-offset bug in dayjs-timezone-iana-plugin.
4806
+ *
4807
+ * @param value - Moment, Day.js, string, Date, or null/undefined
4808
+ * @param timezone - Target IANA timezone (e.g., 'Asia/Kolkata', 'America/New_York')
4809
+ * @returns Day.js object in the target timezone, or null if invalid
4810
+ *
4811
+ * @example
4812
+ * toDayjsInTimezone(moment.tz('2025-04-21 00:00', 'Asia/Kolkata'), 'Asia/Kolkata');
4813
+ * // Returns dayjs representing 2025-04-21 00:00 IST
4814
+ *
4815
+ * @example
4816
+ * toDayjsInTimezone(moment.tz('2025-04-21 00:00', 'UTC'), 'Asia/Kolkata');
4817
+ * // Returns dayjs representing 2025-04-21 05:30 IST
4818
+ */
4819
+ function toDayjsInTimezone(value, timezone) {
4820
+ const dayjsValue = momentToDayjs(value);
4821
+ if (!dayjsValue) return null;
4822
+
4823
+ // Convert via UTC to avoid the double-offset bug in dayjs-timezone-iana-plugin:
4824
+ // calling .tz() on a dayjs that already has a non-zero utcOffset corrupts the value.
4825
+ // Going through .toDate() → dayjs.utc() gives us a clean UTC-mode dayjs that .tz()
4826
+ // correctly converts to the target timezone.
4827
+ return _dayjs.default.utc(dayjsValue.toDate()).tz(timezone);
4828
+ }
4829
+
4784
4830
  /**
4785
4831
  * Converts a Day.js object to Moment.js, preserving timezone and locale information.
4786
4832
  *