@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.
@@ -4234,6 +4234,7 @@ exports.isDayjsObject = isDayjsObject;
4234
4234
  exports.isMomentObject = isMomentObject;
4235
4235
  exports.momentToDayjs = momentToDayjs;
4236
4236
  exports.normalizeDateValue = normalizeDateValue;
4237
+ exports.toDayjsInTimezone = toDayjsInTimezone;
4237
4238
  var _dayjs = _interopRequireDefault(__webpack_require__(87695));
4238
4239
  var _advancedFormat = _interopRequireDefault(__webpack_require__(96833));
4239
4240
  var _customParseFormat = _interopRequireDefault(__webpack_require__(2825));
@@ -4345,7 +4346,23 @@ if (!tzIsCallable) {
4345
4346
  if (_dayjs.default.isDayjs(date)) {
4346
4347
  return date.tz(tzName);
4347
4348
  }
4348
- return (0, _dayjs.default)(date).tz(tzName);
4349
+ // For strings/Dates: interpret the date/time values as being IN the target timezone
4350
+ // (matching moment.tz(string, tz) semantics). dayjs(date).tz(tz) is wrong because
4351
+ // dayjs(date) anchors to the system local timezone, so .tz() converts FROM local TO tz.
4352
+ // Instead: parse as UTC to get raw date/time values, compute the target timezone's offset,
4353
+ // then adjust the UTC timestamp so .tz() produces the intended local time.
4354
+ try {
4355
+ // Validate timezone is a real IANA timezone before applying the offset correction
4356
+ Intl.DateTimeFormat(undefined, {
4357
+ timeZone: tzName
4358
+ });
4359
+ } catch (_unused) {
4360
+ // Invalid timezone — fall back to local time
4361
+ return (0, _dayjs.default)(date);
4362
+ }
4363
+ const asUtc = _dayjs.default.utc(date);
4364
+ const tzOffset = asUtc.tz(tzName).utcOffset(); // target tz offset in minutes
4365
+ return _dayjs.default.utc(asUtc.valueOf() - tzOffset * 60000).tz(tzName);
4349
4366
  } catch (error) {
4350
4367
  // If timezone is invalid, log error and fall back to local time
4351
4368
  logDevError("dayjs.tz: Invalid timezone \"" + tzName + "\"", error);
@@ -4515,7 +4532,10 @@ function momentToDayjs(value) {
4515
4532
  const tz = value.tz();
4516
4533
  if (tz) {
4517
4534
  // Has a named timezone - preserve it
4518
- dayjsObj = (0, _dayjs.default)(date).tz(tz);
4535
+ // dayjs.utc(date) is required here: dayjs(date) anchors to the system local timezone,
4536
+ // causing .tz() to only re-label without converting hours. dayjs.utc(date) creates a
4537
+ // UTC-mode dayjs, which .tz() correctly converts to the target timezone for display.
4538
+ dayjsObj = _dayjs.default.utc(date).tz(tz);
4519
4539
 
4520
4540
  // WORKAROUND: dayjs-timezone-iana-plugin doesn't persist timezone name in standard way
4521
4541
  // Store it manually in $x for round-trip conversion fidelity
@@ -4568,6 +4588,35 @@ function momentToDayjs(value) {
4568
4588
  return null;
4569
4589
  }
4570
4590
 
4591
+ /**
4592
+ * Converts any supported date value (Moment, Day.js, string, Date) to a Day.js object
4593
+ * in the specified timezone. This is the recommended single entry point for timezone-safe
4594
+ * date conversion — it handles moment-to-dayjs conversion and timezone application in one step,
4595
+ * avoiding the double-offset bug in dayjs-timezone-iana-plugin.
4596
+ *
4597
+ * @param value - Moment, Day.js, string, Date, or null/undefined
4598
+ * @param timezone - Target IANA timezone (e.g., 'Asia/Kolkata', 'America/New_York')
4599
+ * @returns Day.js object in the target timezone, or null if invalid
4600
+ *
4601
+ * @example
4602
+ * toDayjsInTimezone(moment.tz('2025-04-21 00:00', 'Asia/Kolkata'), 'Asia/Kolkata');
4603
+ * // Returns dayjs representing 2025-04-21 00:00 IST
4604
+ *
4605
+ * @example
4606
+ * toDayjsInTimezone(moment.tz('2025-04-21 00:00', 'UTC'), 'Asia/Kolkata');
4607
+ * // Returns dayjs representing 2025-04-21 05:30 IST
4608
+ */
4609
+ function toDayjsInTimezone(value, timezone) {
4610
+ const dayjsValue = momentToDayjs(value);
4611
+ if (!dayjsValue) return null;
4612
+
4613
+ // Convert via UTC to avoid the double-offset bug in dayjs-timezone-iana-plugin:
4614
+ // calling .tz() on a dayjs that already has a non-zero utcOffset corrupts the value.
4615
+ // Going through .toDate() → dayjs.utc() gives us a clean UTC-mode dayjs that .tz()
4616
+ // correctly converts to the target timezone.
4617
+ return _dayjs.default.utc(dayjsValue.toDate()).tz(timezone);
4618
+ }
4619
+
4571
4620
  /**
4572
4621
  * Converts a Day.js object to Moment.js, preserving timezone and locale information.
4573
4622
  *