@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.
@@ -3823,6 +3823,7 @@ exports.isDayjsObject = isDayjsObject;
3823
3823
  exports.isMomentObject = isMomentObject;
3824
3824
  exports.momentToDayjs = momentToDayjs;
3825
3825
  exports.normalizeDateValue = normalizeDateValue;
3826
+ exports.toDayjsInTimezone = toDayjsInTimezone;
3826
3827
  var _dayjs = _interopRequireDefault(__webpack_require__(87695));
3827
3828
  var _advancedFormat = _interopRequireDefault(__webpack_require__(96833));
3828
3829
  var _customParseFormat = _interopRequireDefault(__webpack_require__(2825));
@@ -3934,7 +3935,23 @@ if (!tzIsCallable) {
3934
3935
  if (_dayjs.default.isDayjs(date)) {
3935
3936
  return date.tz(tzName);
3936
3937
  }
3937
- return (0, _dayjs.default)(date).tz(tzName);
3938
+ // For strings/Dates: interpret the date/time values as being IN the target timezone
3939
+ // (matching moment.tz(string, tz) semantics). dayjs(date).tz(tz) is wrong because
3940
+ // dayjs(date) anchors to the system local timezone, so .tz() converts FROM local TO tz.
3941
+ // Instead: parse as UTC to get raw date/time values, compute the target timezone's offset,
3942
+ // then adjust the UTC timestamp so .tz() produces the intended local time.
3943
+ try {
3944
+ // Validate timezone is a real IANA timezone before applying the offset correction
3945
+ Intl.DateTimeFormat(undefined, {
3946
+ timeZone: tzName
3947
+ });
3948
+ } catch (_unused) {
3949
+ // Invalid timezone — fall back to local time
3950
+ return (0, _dayjs.default)(date);
3951
+ }
3952
+ const asUtc = _dayjs.default.utc(date);
3953
+ const tzOffset = asUtc.tz(tzName).utcOffset(); // target tz offset in minutes
3954
+ return _dayjs.default.utc(asUtc.valueOf() - tzOffset * 60000).tz(tzName);
3938
3955
  } catch (error) {
3939
3956
  // If timezone is invalid, log error and fall back to local time
3940
3957
  logDevError("dayjs.tz: Invalid timezone \"" + tzName + "\"", error);
@@ -4160,6 +4177,35 @@ function momentToDayjs(value) {
4160
4177
  return null;
4161
4178
  }
4162
4179
 
4180
+ /**
4181
+ * Converts any supported date value (Moment, Day.js, string, Date) to a Day.js object
4182
+ * in the specified timezone. This is the recommended single entry point for timezone-safe
4183
+ * date conversion — it handles moment-to-dayjs conversion and timezone application in one step,
4184
+ * avoiding the double-offset bug in dayjs-timezone-iana-plugin.
4185
+ *
4186
+ * @param value - Moment, Day.js, string, Date, or null/undefined
4187
+ * @param timezone - Target IANA timezone (e.g., 'Asia/Kolkata', 'America/New_York')
4188
+ * @returns Day.js object in the target timezone, or null if invalid
4189
+ *
4190
+ * @example
4191
+ * toDayjsInTimezone(moment.tz('2025-04-21 00:00', 'Asia/Kolkata'), 'Asia/Kolkata');
4192
+ * // Returns dayjs representing 2025-04-21 00:00 IST
4193
+ *
4194
+ * @example
4195
+ * toDayjsInTimezone(moment.tz('2025-04-21 00:00', 'UTC'), 'Asia/Kolkata');
4196
+ * // Returns dayjs representing 2025-04-21 05:30 IST
4197
+ */
4198
+ function toDayjsInTimezone(value, timezone) {
4199
+ const dayjsValue = momentToDayjs(value);
4200
+ if (!dayjsValue) return null;
4201
+
4202
+ // Convert via UTC to avoid the double-offset bug in dayjs-timezone-iana-plugin:
4203
+ // calling .tz() on a dayjs that already has a non-zero utcOffset corrupts the value.
4204
+ // Going through .toDate() → dayjs.utc() gives us a clean UTC-mode dayjs that .tz()
4205
+ // correctly converts to the target timezone.
4206
+ return _dayjs.default.utc(dayjsValue.toDate()).tz(timezone);
4207
+ }
4208
+
4163
4209
  /**
4164
4210
  * Converts a Day.js object to Moment.js, preserving timezone and locale information.
4165
4211
  *