nhb-toolbox 4.28.70 → 4.28.71

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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  All notable changes to the package will be documented here.
6
6
 
7
+ ## [4.28.71] - 2026-02-06
8
+
9
+ - **Fixed** an *issue* in `reconstruct` method of `Chronos` class where the *internal state* of the reconstructed instance was not properly when the timezone offset is different from the local system's timezone offset.
10
+
7
11
  ## [4.28.70] - 2026-02-06
8
12
 
9
13
  - **Added** *new static methods*: `isReconstructable` and `reconstruct` to `Chronos` class for *validating* and *reconstructing* instances from plain objects.
@@ -813,7 +813,11 @@ class Chronos {
813
813
  throw new TypeError('Invalid input for reconstruction!');
814
814
  }
815
815
  const { native, origin, utcOffset, timeZoneName, timeZoneId, $tzTracker } = value;
816
- return new _a(native).#withOrigin(origin, utcOffset, timeZoneName, timeZoneId, $tzTracker);
816
+ const offsetMins = (0, utils_1.extractMinutesFromUTC)(utcOffset);
817
+ const instance = new _a(native);
818
+ const diffMins = instance.getTimeZoneOffsetMinutes() - offsetMins;
819
+ const target = instance.utcOffset === utcOffset ? instance : instance.add(-diffMins, 'minute');
820
+ return target.#withOrigin(origin, utcOffset, timeZoneName, timeZoneId, $tzTracker);
817
821
  }
818
822
  static use(plugin) {
819
823
  if (!_a.#plugins.has(plugin)) {
@@ -166,6 +166,9 @@ function _hasChronosProperties(value) {
166
166
  'timeZoneName',
167
167
  'timeZoneId',
168
168
  ]) &&
169
+ (0, primitives_1.isNonEmptyString)(value.origin) &&
169
170
  ((0, non_primitives_1.isDate)(value.native) || (0, specials_1.isDateString)(value.native)) &&
170
- (0, guards_1.isValidUTCOffset)(value.utcOffset));
171
+ (0, guards_1.isValidUTCOffset)(value.utcOffset) &&
172
+ (0, primitives_1.isNonEmptyString)(value.timeZoneName) &&
173
+ ((0, primitives_1.isNonEmptyString)(value.timeZoneId) || (0, non_primitives_1.isValidArray)(value.timeZoneId)));
171
174
  }
@@ -248,12 +248,19 @@ export type ChronosMethods = $InstanceMethods | $StaticMethods | $PluginMethods;
248
248
  * and convert it to the **equivalent local time** using the current environment's UTC offset.*
249
249
  */
250
250
  export type ChronosInput = number | string | Date | Chronos;
251
+ /** Properties required to reconstruct a `Chronos` instance. */
251
252
  export interface ChronosProperties {
253
+ /** The method or plugin name from which the instance was created. */
252
254
  origin: LooseLiteral<ChronosMethods>;
255
+ /** The native date value, either as a `Date` object or a date string. */
253
256
  native: Date | string;
257
+ /** The UTC offset in `UTC±HH:mm` format. */
254
258
  utcOffset: UTCOffset;
259
+ /** The full time zone name (e.g., `"Pacific Standard Time"`). */
255
260
  timeZoneName: LooseLiteral<TimeZoneName>;
261
+ /** The time zone identifier(s) associated with the instance (e.g., `"Asia/Dhaka"`). */
256
262
  timeZoneId: TimeZoneId;
263
+ /** Optional tracker to identify the instance created by `timeZone` method. */
257
264
  $tzTracker?: $TimeZoneIdentifier | TimeZone | UTCOffset;
258
265
  }
259
266
  /** Represents key of `ChronosStatics` (each static method and property) */
@@ -810,7 +810,11 @@ export class Chronos {
810
810
  throw new TypeError('Invalid input for reconstruction!');
811
811
  }
812
812
  const { native, origin, utcOffset, timeZoneName, timeZoneId, $tzTracker } = value;
813
- return new _a(native).#withOrigin(origin, utcOffset, timeZoneName, timeZoneId, $tzTracker);
813
+ const offsetMins = extractMinutesFromUTC(utcOffset);
814
+ const instance = new _a(native);
815
+ const diffMins = instance.getTimeZoneOffsetMinutes() - offsetMins;
816
+ const target = instance.utcOffset === utcOffset ? instance : instance.add(-diffMins, 'minute');
817
+ return target.#withOrigin(origin, utcOffset, timeZoneName, timeZoneId, $tzTracker);
814
818
  }
815
819
  static use(plugin) {
816
820
  if (!_a.#plugins.has(plugin)) {
@@ -1,5 +1,5 @@
1
- import { isDate, isObjectWithKeys } from '../guards/non-primitives.js';
2
- import { isString } from '../guards/primitives.js';
1
+ import { isDate, isObjectWithKeys, isValidArray } from '../guards/non-primitives.js';
2
+ import { isNonEmptyString, isString } from '../guards/primitives.js';
3
3
  import { isDateString } from '../guards/specials.js';
4
4
  import { getOrdinal } from '../number/utilities.js';
5
5
  import { BN_MONTH_TABLES, BN_SEASONS, BN_YEAR_OFFSET, DAYS, MONTHS, MS_PER_DAY, SORTED_TIME_FORMATS, } from './constants.js';
@@ -144,6 +144,9 @@ export function _hasChronosProperties(value) {
144
144
  'timeZoneName',
145
145
  'timeZoneId',
146
146
  ]) &&
147
+ isNonEmptyString(value.origin) &&
147
148
  (isDate(value.native) || isDateString(value.native)) &&
148
- isValidUTCOffset(value.utcOffset));
149
+ isValidUTCOffset(value.utcOffset) &&
150
+ isNonEmptyString(value.timeZoneName) &&
151
+ (isNonEmptyString(value.timeZoneId) || isValidArray(value.timeZoneId)));
149
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.28.70",
3
+ "version": "4.28.71",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",