@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.
@@ -4067,6 +4067,7 @@ exports.isDayjsObject = isDayjsObject;
4067
4067
  exports.isMomentObject = isMomentObject;
4068
4068
  exports.momentToDayjs = momentToDayjs;
4069
4069
  exports.normalizeDateValue = normalizeDateValue;
4070
+ exports.toDayjsInTimezone = toDayjsInTimezone;
4070
4071
  var _dayjs = _interopRequireDefault(__webpack_require__(87695));
4071
4072
  var _advancedFormat = _interopRequireDefault(__webpack_require__(96833));
4072
4073
  var _customParseFormat = _interopRequireDefault(__webpack_require__(2825));
@@ -4178,7 +4179,23 @@ if (!tzIsCallable) {
4178
4179
  if (_dayjs.default.isDayjs(date)) {
4179
4180
  return date.tz(tzName);
4180
4181
  }
4181
- return (0, _dayjs.default)(date).tz(tzName);
4182
+ // For strings/Dates: interpret the date/time values as being IN the target timezone
4183
+ // (matching moment.tz(string, tz) semantics). dayjs(date).tz(tz) is wrong because
4184
+ // dayjs(date) anchors to the system local timezone, so .tz() converts FROM local TO tz.
4185
+ // Instead: parse as UTC to get raw date/time values, compute the target timezone's offset,
4186
+ // then adjust the UTC timestamp so .tz() produces the intended local time.
4187
+ try {
4188
+ // Validate timezone is a real IANA timezone before applying the offset correction
4189
+ Intl.DateTimeFormat(undefined, {
4190
+ timeZone: tzName
4191
+ });
4192
+ } catch (_unused) {
4193
+ // Invalid timezone — fall back to local time
4194
+ return (0, _dayjs.default)(date);
4195
+ }
4196
+ const asUtc = _dayjs.default.utc(date);
4197
+ const tzOffset = asUtc.tz(tzName).utcOffset(); // target tz offset in minutes
4198
+ return _dayjs.default.utc(asUtc.valueOf() - tzOffset * 60000).tz(tzName);
4182
4199
  } catch (error) {
4183
4200
  // If timezone is invalid, log error and fall back to local time
4184
4201
  logDevError("dayjs.tz: Invalid timezone \"" + tzName + "\"", error);
@@ -4404,6 +4421,35 @@ function momentToDayjs(value) {
4404
4421
  return null;
4405
4422
  }
4406
4423
 
4424
+ /**
4425
+ * Converts any supported date value (Moment, Day.js, string, Date) to a Day.js object
4426
+ * in the specified timezone. This is the recommended single entry point for timezone-safe
4427
+ * date conversion — it handles moment-to-dayjs conversion and timezone application in one step,
4428
+ * avoiding the double-offset bug in dayjs-timezone-iana-plugin.
4429
+ *
4430
+ * @param value - Moment, Day.js, string, Date, or null/undefined
4431
+ * @param timezone - Target IANA timezone (e.g., 'Asia/Kolkata', 'America/New_York')
4432
+ * @returns Day.js object in the target timezone, or null if invalid
4433
+ *
4434
+ * @example
4435
+ * toDayjsInTimezone(moment.tz('2025-04-21 00:00', 'Asia/Kolkata'), 'Asia/Kolkata');
4436
+ * // Returns dayjs representing 2025-04-21 00:00 IST
4437
+ *
4438
+ * @example
4439
+ * toDayjsInTimezone(moment.tz('2025-04-21 00:00', 'UTC'), 'Asia/Kolkata');
4440
+ * // Returns dayjs representing 2025-04-21 05:30 IST
4441
+ */
4442
+ function toDayjsInTimezone(value, timezone) {
4443
+ const dayjsValue = momentToDayjs(value);
4444
+ if (!dayjsValue) return null;
4445
+
4446
+ // Convert via UTC to avoid the double-offset bug in dayjs-timezone-iana-plugin:
4447
+ // calling .tz() on a dayjs that already has a non-zero utcOffset corrupts the value.
4448
+ // Going through .toDate() → dayjs.utc() gives us a clean UTC-mode dayjs that .tz()
4449
+ // correctly converts to the target timezone.
4450
+ return _dayjs.default.utc(dayjsValue.toDate()).tz(timezone);
4451
+ }
4452
+
4407
4453
  /**
4408
4454
  * Converts a Day.js object to Moment.js, preserving timezone and locale information.
4409
4455
  *