nhb-toolbox 4.26.60 → 4.26.64

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
@@ -6,6 +6,18 @@ All notable changes to the package will be documented here.
6
6
 
7
7
  ---
8
8
 
9
+ ## [4.26.64] - 2025-11-17
10
+
11
+ ### 🕧 Fixes in Chronos
12
+
13
+ - **Fixed** *timestamp handling*: `timestamp`, `unix`, `valueOf()`, and `getTimeStamp()` now consistently use/return the correct **universal timestamp**.
14
+ - **Improved** `min(...)` and `max(...)` methods to return a new *immutable* `Chronos` instance while preserving the *internal state* of the **winning instance** (timezone info, offset, and origin).
15
+
16
+ ## [4.26.61] - 2025-11-17
17
+
18
+ - **Fixed** issue with `Chronos` *format methods* not formatting correctly when `useUTC` is `true`.
19
+ - **Updated** *tsdoc* for some `Chronos` methods.
20
+
9
21
  ## [4.26.60] - 2025-11-16
10
22
 
11
23
  - **Fixed** an *issue* in `Chronos` class where chaining *calculation methods* after `timeZone`, `toLocal`, `toUTC`, or other *offset-adjusting methods* resulted in *incorrect* time values.
@@ -97,6 +97,9 @@ class Chronos {
97
97
  $getNativeTimeZoneId() {
98
98
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
99
99
  }
100
+ get #timestamp() {
101
+ return this.#date.getTime();
102
+ }
100
103
  #toNewDate(value) {
101
104
  const date = value instanceof _a ? value.toDate() : new Date(value ?? Date.now());
102
105
  if (isNaN(date.getTime())) {
@@ -139,14 +142,18 @@ class Chronos {
139
142
  }
140
143
  #format(format, useUTC = false) {
141
144
  const $date = this.#date;
142
- const year = useUTC ? $date.getUTCFullYear() : $date.getFullYear();
143
- const month = useUTC ? $date.getUTCMonth() : $date.getMonth();
144
- const day = useUTC ? $date.getUTCDay() : $date.getDay();
145
- const date = useUTC ? $date.getUTCDate() : $date.getDate();
146
- const hours = useUTC ? $date.getUTCHours() : $date.getHours();
147
- const minutes = useUTC ? $date.getUTCMinutes() : $date.getMinutes();
148
- const seconds = useUTC ? $date.getUTCSeconds() : $date.getSeconds();
149
- const milliseconds = useUTC ? $date.getUTCMilliseconds() : $date.getMilliseconds();
145
+ const $utcDate = this.toDate();
146
+ const _getUnitValue = (suffix) => {
147
+ return useUTC ? $utcDate[`getUTC${suffix}`]() : $date[`get${suffix}`]();
148
+ };
149
+ const year = _getUnitValue('FullYear');
150
+ const month = _getUnitValue('Month');
151
+ const day = _getUnitValue('Day');
152
+ const date = _getUnitValue('Date');
153
+ const hours = _getUnitValue('Hours');
154
+ const minutes = _getUnitValue('Minutes');
155
+ const seconds = _getUnitValue('Seconds');
156
+ const milliseconds = _getUnitValue('Milliseconds');
150
157
  const timeZone = useUTC ? 'Z' : this.getTimeZoneOffset();
151
158
  const dateComponents = {
152
159
  YYYY: String(year),
@@ -201,10 +208,6 @@ class Chronos {
201
208
  }
202
209
  return result;
203
210
  }
204
- #toLocalISOString() {
205
- const pad = (n, p = 2) => String(n).padStart(p, '0');
206
- return `${this.year}-${pad(this.month + 1)}-${pad(this.date)}T${pad(this.hour)}:${pad(this.minute)}:${pad(this.second)}.${pad(this.millisecond, 3)}${this.#offset.slice(3)}`;
207
- }
208
211
  #removeUTCFromISO(local = false) {
209
212
  return local ?
210
213
  this.toLocalISOString().replace(/\.\d+(Z|[+-]\d{2}:\d{2})?$/, '')
@@ -242,10 +245,10 @@ class Chronos {
242
245
  return (this.month + 1);
243
246
  }
244
247
  get unix() {
245
- return Math.floor(this.#date.getTime() / 1000);
248
+ return Math.floor(this.getTimeStamp() / 1000);
246
249
  }
247
250
  get timestamp() {
248
- return this.#date.getTime();
251
+ return this.getTimeStamp();
249
252
  }
250
253
  get lastDateOfMonth() {
251
254
  return this.daysInMonth();
@@ -274,7 +277,7 @@ class Chronos {
274
277
  .concat(` (${this.timeZoneName})`);
275
278
  }
276
279
  toLocalISOString() {
277
- return this.#toLocalISOString();
280
+ return this.#format('YYYY-MM-DDTHH:mm:ss.mssZZ');
278
281
  }
279
282
  toISOString() {
280
283
  return this.toDate().toISOString();
@@ -283,7 +286,7 @@ class Chronos {
283
286
  return this.toUTC().toDate().toLocaleString(locales, options);
284
287
  }
285
288
  getTimeStamp() {
286
- return this.#date.getTime();
289
+ return this.toDate().getTime();
287
290
  }
288
291
  format(format, useUTC = false) {
289
292
  return this.#format(format ?? 'dd, mmm DD, YYYY HH:mm:ss', useUTC);
@@ -292,12 +295,7 @@ class Chronos {
292
295
  return this.#format(format ?? 'dd, mmm DD, YYYY HH:mm:ss', useUTC);
293
296
  }
294
297
  formatUTC(format = 'dd, mmm DD, YYYY HH:mm:ss:mss') {
295
- switch (this.#offset) {
296
- case 'UTC+00:00':
297
- return this.#format(format, false);
298
- default:
299
- return this.#format(format, true);
300
- }
298
+ return this.#format(format, true);
301
299
  }
302
300
  addSeconds(seconds) {
303
301
  return this.#cloneStates(this.add(seconds, 'second'), 'addSeconds');
@@ -324,31 +322,31 @@ class Chronos {
324
322
  return (0, guards_1.isLeapYear)(year ?? this.year);
325
323
  }
326
324
  isEqual(other) {
327
- const time = other instanceof _a ? other : new _a(other);
328
- return this.timestamp === time.timestamp;
325
+ const time = _a.#cast(other);
326
+ return this.#timestamp === time.#timestamp;
329
327
  }
330
328
  isEqualOrBefore(other) {
331
- const time = other instanceof _a ? other : new _a(other);
332
- return this.timestamp <= time.timestamp;
329
+ const time = _a.#cast(other);
330
+ return this.#timestamp <= time.#timestamp;
333
331
  }
334
332
  isEqualOrAfter(other) {
335
- const time = other instanceof _a ? other : new _a(other);
336
- return this.timestamp >= time.timestamp;
333
+ const time = _a.#cast(other);
334
+ return this.#timestamp >= time.#timestamp;
337
335
  }
338
336
  isSame(other, unit, weekStartsOn = 0) {
339
- const time = other instanceof _a ? other : new _a(other);
340
- return (this.startOf(unit, weekStartsOn).timestamp ===
341
- time.startOf(unit, weekStartsOn).timestamp);
337
+ const time = _a.#cast(other);
338
+ return (this.startOf(unit, weekStartsOn).#timestamp ===
339
+ time.startOf(unit, weekStartsOn).#timestamp);
342
340
  }
343
341
  isBefore(other, unit, weekStartsOn = 0) {
344
- const time = other instanceof _a ? other : new _a(other);
345
- return (this.startOf(unit, weekStartsOn).timestamp <
346
- time.startOf(unit, weekStartsOn).timestamp);
342
+ const time = _a.#cast(other);
343
+ return (this.startOf(unit, weekStartsOn).#timestamp <
344
+ time.startOf(unit, weekStartsOn).#timestamp);
347
345
  }
348
346
  isAfter(other, unit, weekStartsOn = 0) {
349
- const time = other instanceof _a ? other : new _a(other);
350
- return (this.startOf(unit, weekStartsOn).timestamp >
351
- time.startOf(unit, weekStartsOn).timestamp);
347
+ const time = _a.#cast(other);
348
+ return (this.startOf(unit, weekStartsOn).#timestamp >
349
+ time.startOf(unit, weekStartsOn).#timestamp);
352
350
  }
353
351
  isSameOrBefore(other, unit, weekStartsOn = 0) {
354
352
  return (this.isSame(other, unit, weekStartsOn) || this.isBefore(other, unit, weekStartsOn));
@@ -515,7 +513,7 @@ class Chronos {
515
513
  return this.#cloneStates(new _a(d), 'set');
516
514
  }
517
515
  diff(other, unit) {
518
- const time = other instanceof _a ? other : new _a(other);
516
+ const time = _a.#cast(other);
519
517
  const msDiff = this.#date.getTime() - time.#date.getTime();
520
518
  switch (unit) {
521
519
  case 'millisecond':
@@ -652,9 +650,6 @@ class Chronos {
652
650
  return (0, utils_1.extractMinutesFromUTC)(this.#offset);
653
651
  }
654
652
  toUTC() {
655
- if (this.#offset === 'UTC+00:00') {
656
- return this.#withOrigin('toUTC', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
657
- }
658
653
  const offset = this.getTimeZoneOffsetMinutes();
659
654
  const utc = new Date(this.#date.getTime() - offset * 60 * 1000);
660
655
  return new _a(utc).#withOrigin('toUTC', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
@@ -794,9 +789,6 @@ class Chronos {
794
789
  }
795
790
  static utc(dateLike) {
796
791
  const chronos = new _a(dateLike);
797
- if (chronos.#offset === 'UTC+00:00') {
798
- return chronos.#withOrigin('utc', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
799
- }
800
792
  const offset = chronos.getTimeZoneOffsetMinutes();
801
793
  const utc = new Date(chronos.#date.getTime() - offset * 60 * 1000);
802
794
  return new _a(utc).#withOrigin('utc', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
@@ -839,10 +831,24 @@ class Chronos {
839
831
  return result;
840
832
  }
841
833
  static min(...dates) {
842
- return new _a(Math.min(...dates.map((d) => new _a(d).valueOf()))).#withOrigin('min');
834
+ let winner = _a.#cast(dates[0]);
835
+ for (const d of dates) {
836
+ const c = _a.#cast(d);
837
+ if (c.timestamp < winner.timestamp) {
838
+ winner = c;
839
+ }
840
+ }
841
+ return winner.#cloneStates(winner, winner.#ORIGIN !== 'root' ? winner.#ORIGIN : 'min');
843
842
  }
844
843
  static max(...dates) {
845
- return new _a(Math.max(...dates.map((d) => new _a(d).valueOf()))).#withOrigin('max');
844
+ let winner = _a.#cast(dates[0]);
845
+ for (const d of dates) {
846
+ const c = _a.#cast(d);
847
+ if (c.timestamp > winner.timestamp) {
848
+ winner = c;
849
+ }
850
+ }
851
+ return winner.#cloneStates(winner, winner.#ORIGIN !== 'root' ? winner.#ORIGIN : 'max');
846
852
  }
847
853
  static isLeapYear(date) {
848
854
  let year;
@@ -877,6 +883,9 @@ class Chronos {
877
883
  static register(plugin) {
878
884
  _a.use(plugin);
879
885
  }
886
+ static #cast(date) {
887
+ return date instanceof _a ? date : new _a(date);
888
+ }
880
889
  }
881
890
  exports.Chronos = Chronos;
882
891
  _a = Chronos;
@@ -28,8 +28,7 @@ const durationPlugin = (ChronosClass) => {
28
28
  const from = isFuture ? now : target;
29
29
  const to = isFuture ? target : now;
30
30
  const _getDiff = (suffix) => {
31
- const method = ('get' + suffix);
32
- return to[method]() - from[method]();
31
+ return to[`get${suffix}`]() - from[`get${suffix}`]();
33
32
  };
34
33
  let years = _getDiff('FullYear');
35
34
  let months = _getDiff('Month');
@@ -3,7 +3,7 @@ import type { LooseLiteral, TupleOf } from '../utils/types';
3
3
  import { INTERNALS } from './constants';
4
4
  import type { $TimeZoneIdentifier, $UTCOffset, ChronosInput, ChronosInternals, ChronosMethods, ChronosObject, ChronosPlugin, ChronosWithOptions, DateRangeOptions, DateTimeFormatOptions, FormatOptions, LocalesArguments, Milliseconds, MonthName, Quarter, RangeWithDates, RelativeDateRange, RelativeRangeOptions, StrictFormat, TimeParts, TimeUnit, TimeUnitValue, TimeZone, TimeZoneId, TimeZoneIdNative, TimeZoneName, TimeZoneNameNative, UTCOffset, WeekDay } from './types';
5
5
  /**
6
- * * Creates a new immutable `Chronos` instance.
6
+ * * Creates a new immutable local-aware `Chronos` instance.
7
7
  *
8
8
  * **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
9
9
  * and convert it to the **equivalent local time** using the current environment's UTC offset.*
@@ -39,9 +39,9 @@ export declare class Chronos {
39
39
  */
40
40
  native: Date;
41
41
  /**
42
- * * Current UTC offset in `UTC±HH:mm` format.
42
+ * * Current (time zone) UTC offset in `UTC±HH:mm` format.
43
43
  *
44
- * - Also accessible via {@link getUTCOffset} instance method without `UTC` prefix (in `±HH:mm` format).
44
+ * - Also accessible via {@link getTimeZoneOffset} instance method without `UTC` prefix (returns in `±HH:mm` format).
45
45
  */
46
46
  utcOffset: UTCOffset;
47
47
  /**
@@ -68,7 +68,7 @@ export declare class Chronos {
68
68
  /** Tracker to identify the instance created by {@link https://toolbox.nazmul-nhb.dev/docs/classes/Chronos/conversion#timezone timeZone} method */
69
69
  protected $tzTracker?: $TimeZoneIdentifier | TimeZone | UTCOffset;
70
70
  /**
71
- * * Creates a new immutable `Chronos` instance.
71
+ * * Creates a new immutable local-aware `Chronos` instance.
72
72
  *
73
73
  * Accepts no arguments (defaults to now).
74
74
  *
@@ -76,7 +76,7 @@ export declare class Chronos {
76
76
  */
77
77
  constructor();
78
78
  /**
79
- * * Creates a new immutable `Chronos` instance.
79
+ * * Creates a new immutable local-aware `Chronos` instance.
80
80
  *
81
81
  * @param value - A date value in `number`, it should be a timestamp (milliseconds since the Unix epoch).
82
82
  *
@@ -84,7 +84,7 @@ export declare class Chronos {
84
84
  */
85
85
  constructor(value: number);
86
86
  /**
87
- * * Creates a new immutable `Chronos` instance.
87
+ * * Creates a new immutable local-aware `Chronos` instance.
88
88
  *
89
89
  * **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
90
90
  * and convert it to the **equivalent local time** using the current environment's UTC offset.*
@@ -95,7 +95,7 @@ export declare class Chronos {
95
95
  */
96
96
  constructor(value: string);
97
97
  /**
98
- * * Creates a new immutable `Chronos` instance.
98
+ * * Creates a new immutable local-aware `Chronos` instance.
99
99
  *
100
100
  * @param value - A date value as `Date` object, it will be used as is.
101
101
  *
@@ -103,7 +103,7 @@ export declare class Chronos {
103
103
  */
104
104
  constructor(value: Date);
105
105
  /**
106
- * * Creates a new immutable `Chronos` instance.
106
+ * * Creates a new immutable local-aware `Chronos` instance.
107
107
  *
108
108
  * @param value - A date value as `Chronos` object.
109
109
  *
@@ -111,7 +111,7 @@ export declare class Chronos {
111
111
  */
112
112
  constructor(value: Chronos);
113
113
  /**
114
- * * Creates a new immutable `Chronos` instance.
114
+ * * Creates a new immutable local-aware `Chronos` instance.
115
115
  *
116
116
  * **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
117
117
  * and convert it to the **equivalent local time** using the current environment's UTC offset.*
@@ -128,7 +128,7 @@ export declare class Chronos {
128
128
  */
129
129
  constructor(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number);
130
130
  /**
131
- * * Creates a new immutable `Chronos` instance.
131
+ * * Creates a new immutable local-aware `Chronos` instance.
132
132
  *
133
133
  * **Note**: *If a date is provided **without a time component**, the instance will default to `00:00:00.000` UTC
134
134
  * and convert it to the **equivalent local time** using the current environment's UTC offset.*
@@ -756,13 +756,29 @@ export declare class Chronos {
756
756
  */
757
757
  static getDatesForDay(day: WeekDay, options?: DateRangeOptions): string[];
758
758
  /**
759
- * @static Returns earliest Chronos.
760
- * @param dates Date inputs.
759
+ * @static Returns the earliest `Chronos` instance based on the underlying universal {@link timestamp}.
760
+ *
761
+ * @remarks
762
+ * - All inputs are normalized to `Chronos` instances before comparison.
763
+ * - Comparison is always performed using each instance's **UTC timestamp**, ensuring a consistent and timezone-agnostic result.
764
+ * - When exactly two values are provided, the first value becomes the initial candidate; if the second value represents an earlier moment in time, it replaces the candidate.
765
+ * - The returned value is **not** one of the input objects. A new immutable `Chronos` instance is always created. Its internal timezone, offset, name, and tracking information are cloned from the winning input instance.
766
+ *
767
+ * @param dates A list of Chronos-compatible inputs (`string`, `number`, `Date` or `Chronos`).
768
+ * @returns A new `Chronos` instance representing the earliest moment.
761
769
  */
762
770
  static min(...dates: ChronosInput[]): Chronos;
763
771
  /**
764
- * @static Returns latest Chronos.
765
- * @param dates Date inputs.
772
+ * @static Returns the latest `Chronos` instance based on the underlying universal {@link timestamp}.
773
+ *
774
+ * @remarks
775
+ * - All inputs are normalized to `Chronos` instances before comparison.
776
+ * - Comparison is always performed using each instance's **UTC timestamp**, ensuring a consistent and timezone-agnostic result.
777
+ * - When exactly two values are provided, the first value becomes the initial candidate; if the second value represents a later moment in time, it replaces the candidate.
778
+ * - The returned value is **not** one of the input objects. A new immutable `Chronos` instance is always created. Its internal timezone, offset, name, and tracking information are cloned from the winning input instance.
779
+ *
780
+ * @param dates A list of Chronos-compatible inputs (`string`, `number`, `Date` or `Chronos`).
781
+ * @returns A new `Chronos` instance representing the latest moment.
766
782
  */
767
783
  static max(...dates: ChronosInput[]): Chronos;
768
784
  /**
@@ -48,6 +48,7 @@ import type { ChronosStatics } from './types';
48
48
  * chronos.formatTimePart(time: string, format?: TimeParts): string;
49
49
  * chronos.getDatesForDay(day: WeekDay, options?: WeekdayOptions): string[];
50
50
  * chronos.use(plugin: ChronosPlugin): void;
51
+ * chronos.register(plugin: ChronosPlugin): void;
51
52
  * ```
52
53
  */
53
54
  declare const chronosStatics: ChronosStatics;
@@ -82,6 +82,8 @@ export type Second = (typeof SECOND_FORMATS)[number];
82
82
  export type Millisecond = (typeof MILLISECOND_FORMATS)[number];
83
83
  /** Time formats in either capital or lowercase `am/pm` format */
84
84
  export type TimeFormats = (typeof TIME_FORMATS)[number];
85
+ /** Represents a valid unit suffix for {@link Date} getter methods (e.g., 'getFullYear', 'getMonth' etc.). */
86
+ export type $DateUnit = 'FullYear' | 'Month' | 'Day' | 'Date' | 'Hours' | 'Minutes' | 'Seconds' | 'Milliseconds';
85
87
  /** Standard union formats for `Chronos`. */
86
88
  export type ChronosFormat = Year | Month | Day | MonthDate | Hour | Minute | Second | Millisecond | TimeFormats | 'ZZ';
87
89
  /** Standard date formats. */
@@ -94,6 +94,9 @@ export class Chronos {
94
94
  $getNativeTimeZoneId() {
95
95
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
96
96
  }
97
+ get #timestamp() {
98
+ return this.#date.getTime();
99
+ }
97
100
  #toNewDate(value) {
98
101
  const date = value instanceof _a ? value.toDate() : new Date(value ?? Date.now());
99
102
  if (isNaN(date.getTime())) {
@@ -136,14 +139,18 @@ export class Chronos {
136
139
  }
137
140
  #format(format, useUTC = false) {
138
141
  const $date = this.#date;
139
- const year = useUTC ? $date.getUTCFullYear() : $date.getFullYear();
140
- const month = useUTC ? $date.getUTCMonth() : $date.getMonth();
141
- const day = useUTC ? $date.getUTCDay() : $date.getDay();
142
- const date = useUTC ? $date.getUTCDate() : $date.getDate();
143
- const hours = useUTC ? $date.getUTCHours() : $date.getHours();
144
- const minutes = useUTC ? $date.getUTCMinutes() : $date.getMinutes();
145
- const seconds = useUTC ? $date.getUTCSeconds() : $date.getSeconds();
146
- const milliseconds = useUTC ? $date.getUTCMilliseconds() : $date.getMilliseconds();
142
+ const $utcDate = this.toDate();
143
+ const _getUnitValue = (suffix) => {
144
+ return useUTC ? $utcDate[`getUTC${suffix}`]() : $date[`get${suffix}`]();
145
+ };
146
+ const year = _getUnitValue('FullYear');
147
+ const month = _getUnitValue('Month');
148
+ const day = _getUnitValue('Day');
149
+ const date = _getUnitValue('Date');
150
+ const hours = _getUnitValue('Hours');
151
+ const minutes = _getUnitValue('Minutes');
152
+ const seconds = _getUnitValue('Seconds');
153
+ const milliseconds = _getUnitValue('Milliseconds');
147
154
  const timeZone = useUTC ? 'Z' : this.getTimeZoneOffset();
148
155
  const dateComponents = {
149
156
  YYYY: String(year),
@@ -198,10 +205,6 @@ export class Chronos {
198
205
  }
199
206
  return result;
200
207
  }
201
- #toLocalISOString() {
202
- const pad = (n, p = 2) => String(n).padStart(p, '0');
203
- return `${this.year}-${pad(this.month + 1)}-${pad(this.date)}T${pad(this.hour)}:${pad(this.minute)}:${pad(this.second)}.${pad(this.millisecond, 3)}${this.#offset.slice(3)}`;
204
- }
205
208
  #removeUTCFromISO(local = false) {
206
209
  return local ?
207
210
  this.toLocalISOString().replace(/\.\d+(Z|[+-]\d{2}:\d{2})?$/, '')
@@ -239,10 +242,10 @@ export class Chronos {
239
242
  return (this.month + 1);
240
243
  }
241
244
  get unix() {
242
- return Math.floor(this.#date.getTime() / 1000);
245
+ return Math.floor(this.getTimeStamp() / 1000);
243
246
  }
244
247
  get timestamp() {
245
- return this.#date.getTime();
248
+ return this.getTimeStamp();
246
249
  }
247
250
  get lastDateOfMonth() {
248
251
  return this.daysInMonth();
@@ -271,7 +274,7 @@ export class Chronos {
271
274
  .concat(` (${this.timeZoneName})`);
272
275
  }
273
276
  toLocalISOString() {
274
- return this.#toLocalISOString();
277
+ return this.#format('YYYY-MM-DDTHH:mm:ss.mssZZ');
275
278
  }
276
279
  toISOString() {
277
280
  return this.toDate().toISOString();
@@ -280,7 +283,7 @@ export class Chronos {
280
283
  return this.toUTC().toDate().toLocaleString(locales, options);
281
284
  }
282
285
  getTimeStamp() {
283
- return this.#date.getTime();
286
+ return this.toDate().getTime();
284
287
  }
285
288
  format(format, useUTC = false) {
286
289
  return this.#format(format ?? 'dd, mmm DD, YYYY HH:mm:ss', useUTC);
@@ -289,12 +292,7 @@ export class Chronos {
289
292
  return this.#format(format ?? 'dd, mmm DD, YYYY HH:mm:ss', useUTC);
290
293
  }
291
294
  formatUTC(format = 'dd, mmm DD, YYYY HH:mm:ss:mss') {
292
- switch (this.#offset) {
293
- case 'UTC+00:00':
294
- return this.#format(format, false);
295
- default:
296
- return this.#format(format, true);
297
- }
295
+ return this.#format(format, true);
298
296
  }
299
297
  addSeconds(seconds) {
300
298
  return this.#cloneStates(this.add(seconds, 'second'), 'addSeconds');
@@ -321,31 +319,31 @@ export class Chronos {
321
319
  return isLeapYear(year ?? this.year);
322
320
  }
323
321
  isEqual(other) {
324
- const time = other instanceof _a ? other : new _a(other);
325
- return this.timestamp === time.timestamp;
322
+ const time = _a.#cast(other);
323
+ return this.#timestamp === time.#timestamp;
326
324
  }
327
325
  isEqualOrBefore(other) {
328
- const time = other instanceof _a ? other : new _a(other);
329
- return this.timestamp <= time.timestamp;
326
+ const time = _a.#cast(other);
327
+ return this.#timestamp <= time.#timestamp;
330
328
  }
331
329
  isEqualOrAfter(other) {
332
- const time = other instanceof _a ? other : new _a(other);
333
- return this.timestamp >= time.timestamp;
330
+ const time = _a.#cast(other);
331
+ return this.#timestamp >= time.#timestamp;
334
332
  }
335
333
  isSame(other, unit, weekStartsOn = 0) {
336
- const time = other instanceof _a ? other : new _a(other);
337
- return (this.startOf(unit, weekStartsOn).timestamp ===
338
- time.startOf(unit, weekStartsOn).timestamp);
334
+ const time = _a.#cast(other);
335
+ return (this.startOf(unit, weekStartsOn).#timestamp ===
336
+ time.startOf(unit, weekStartsOn).#timestamp);
339
337
  }
340
338
  isBefore(other, unit, weekStartsOn = 0) {
341
- const time = other instanceof _a ? other : new _a(other);
342
- return (this.startOf(unit, weekStartsOn).timestamp <
343
- time.startOf(unit, weekStartsOn).timestamp);
339
+ const time = _a.#cast(other);
340
+ return (this.startOf(unit, weekStartsOn).#timestamp <
341
+ time.startOf(unit, weekStartsOn).#timestamp);
344
342
  }
345
343
  isAfter(other, unit, weekStartsOn = 0) {
346
- const time = other instanceof _a ? other : new _a(other);
347
- return (this.startOf(unit, weekStartsOn).timestamp >
348
- time.startOf(unit, weekStartsOn).timestamp);
344
+ const time = _a.#cast(other);
345
+ return (this.startOf(unit, weekStartsOn).#timestamp >
346
+ time.startOf(unit, weekStartsOn).#timestamp);
349
347
  }
350
348
  isSameOrBefore(other, unit, weekStartsOn = 0) {
351
349
  return (this.isSame(other, unit, weekStartsOn) || this.isBefore(other, unit, weekStartsOn));
@@ -512,7 +510,7 @@ export class Chronos {
512
510
  return this.#cloneStates(new _a(d), 'set');
513
511
  }
514
512
  diff(other, unit) {
515
- const time = other instanceof _a ? other : new _a(other);
513
+ const time = _a.#cast(other);
516
514
  const msDiff = this.#date.getTime() - time.#date.getTime();
517
515
  switch (unit) {
518
516
  case 'millisecond':
@@ -649,9 +647,6 @@ export class Chronos {
649
647
  return extractMinutesFromUTC(this.#offset);
650
648
  }
651
649
  toUTC() {
652
- if (this.#offset === 'UTC+00:00') {
653
- return this.#withOrigin('toUTC', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
654
- }
655
650
  const offset = this.getTimeZoneOffsetMinutes();
656
651
  const utc = new Date(this.#date.getTime() - offset * 60 * 1000);
657
652
  return new _a(utc).#withOrigin('toUTC', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
@@ -791,9 +786,6 @@ export class Chronos {
791
786
  }
792
787
  static utc(dateLike) {
793
788
  const chronos = new _a(dateLike);
794
- if (chronos.#offset === 'UTC+00:00') {
795
- return chronos.#withOrigin('utc', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
796
- }
797
789
  const offset = chronos.getTimeZoneOffsetMinutes();
798
790
  const utc = new Date(chronos.#date.getTime() - offset * 60 * 1000);
799
791
  return new _a(utc).#withOrigin('utc', 'UTC+00:00', 'Greenwich Mean Time', 'UTC');
@@ -836,10 +828,24 @@ export class Chronos {
836
828
  return result;
837
829
  }
838
830
  static min(...dates) {
839
- return new _a(Math.min(...dates.map((d) => new _a(d).valueOf()))).#withOrigin('min');
831
+ let winner = _a.#cast(dates[0]);
832
+ for (const d of dates) {
833
+ const c = _a.#cast(d);
834
+ if (c.timestamp < winner.timestamp) {
835
+ winner = c;
836
+ }
837
+ }
838
+ return winner.#cloneStates(winner, winner.#ORIGIN !== 'root' ? winner.#ORIGIN : 'min');
840
839
  }
841
840
  static max(...dates) {
842
- return new _a(Math.max(...dates.map((d) => new _a(d).valueOf()))).#withOrigin('max');
841
+ let winner = _a.#cast(dates[0]);
842
+ for (const d of dates) {
843
+ const c = _a.#cast(d);
844
+ if (c.timestamp > winner.timestamp) {
845
+ winner = c;
846
+ }
847
+ }
848
+ return winner.#cloneStates(winner, winner.#ORIGIN !== 'root' ? winner.#ORIGIN : 'max');
843
849
  }
844
850
  static isLeapYear(date) {
845
851
  let year;
@@ -874,6 +880,9 @@ export class Chronos {
874
880
  static register(plugin) {
875
881
  _a.use(plugin);
876
882
  }
883
+ static #cast(date) {
884
+ return date instanceof _a ? date : new _a(date);
885
+ }
877
886
  }
878
887
  _a = Chronos;
879
888
  export { chronos } from './chronos-fn.js';
@@ -25,8 +25,7 @@ export const durationPlugin = (ChronosClass) => {
25
25
  const from = isFuture ? now : target;
26
26
  const to = isFuture ? target : now;
27
27
  const _getDiff = (suffix) => {
28
- const method = ('get' + suffix);
29
- return to[method]() - from[method]();
28
+ return to[`get${suffix}`]() - from[`get${suffix}`]();
30
29
  };
31
30
  let years = _getDiff('FullYear');
32
31
  let months = _getDiff('Month');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "4.26.60",
3
+ "version": "4.26.64",
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",