nhb-toolbox 4.26.61 → 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 +7 -0
- package/dist/cjs/date/Chronos.js +41 -21
- package/dist/dts/date/Chronos.d.ts +20 -4
- package/dist/dts/date/chronos-fn.d.ts +1 -0
- package/dist/esm/date/Chronos.js +41 -21
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,13 @@ 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
|
+
|
|
9
16
|
## [4.26.61] - 2025-11-17
|
|
10
17
|
|
|
11
18
|
- **Fixed** issue with `Chronos` *format methods* not formatting correctly when `useUTC` is `true`.
|
package/dist/cjs/date/Chronos.js
CHANGED
|
@@ -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())) {
|
|
@@ -242,10 +245,10 @@ class Chronos {
|
|
|
242
245
|
return (this.month + 1);
|
|
243
246
|
}
|
|
244
247
|
get unix() {
|
|
245
|
-
return Math.floor(this
|
|
248
|
+
return Math.floor(this.getTimeStamp() / 1000);
|
|
246
249
|
}
|
|
247
250
|
get timestamp() {
|
|
248
|
-
return this
|
|
251
|
+
return this.getTimeStamp();
|
|
249
252
|
}
|
|
250
253
|
get lastDateOfMonth() {
|
|
251
254
|
return this.daysInMonth();
|
|
@@ -283,7 +286,7 @@ class Chronos {
|
|
|
283
286
|
return this.toUTC().toDate().toLocaleString(locales, options);
|
|
284
287
|
}
|
|
285
288
|
getTimeStamp() {
|
|
286
|
-
return this
|
|
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);
|
|
@@ -319,31 +322,31 @@ class Chronos {
|
|
|
319
322
|
return (0, guards_1.isLeapYear)(year ?? this.year);
|
|
320
323
|
}
|
|
321
324
|
isEqual(other) {
|
|
322
|
-
const time =
|
|
323
|
-
return this
|
|
325
|
+
const time = _a.#cast(other);
|
|
326
|
+
return this.#timestamp === time.#timestamp;
|
|
324
327
|
}
|
|
325
328
|
isEqualOrBefore(other) {
|
|
326
|
-
const time =
|
|
327
|
-
return this
|
|
329
|
+
const time = _a.#cast(other);
|
|
330
|
+
return this.#timestamp <= time.#timestamp;
|
|
328
331
|
}
|
|
329
332
|
isEqualOrAfter(other) {
|
|
330
|
-
const time =
|
|
331
|
-
return this
|
|
333
|
+
const time = _a.#cast(other);
|
|
334
|
+
return this.#timestamp >= time.#timestamp;
|
|
332
335
|
}
|
|
333
336
|
isSame(other, unit, weekStartsOn = 0) {
|
|
334
|
-
const time =
|
|
335
|
-
return (this.startOf(unit, weekStartsOn)
|
|
336
|
-
time.startOf(unit, weekStartsOn)
|
|
337
|
+
const time = _a.#cast(other);
|
|
338
|
+
return (this.startOf(unit, weekStartsOn).#timestamp ===
|
|
339
|
+
time.startOf(unit, weekStartsOn).#timestamp);
|
|
337
340
|
}
|
|
338
341
|
isBefore(other, unit, weekStartsOn = 0) {
|
|
339
|
-
const time =
|
|
340
|
-
return (this.startOf(unit, weekStartsOn)
|
|
341
|
-
time.startOf(unit, weekStartsOn)
|
|
342
|
+
const time = _a.#cast(other);
|
|
343
|
+
return (this.startOf(unit, weekStartsOn).#timestamp <
|
|
344
|
+
time.startOf(unit, weekStartsOn).#timestamp);
|
|
342
345
|
}
|
|
343
346
|
isAfter(other, unit, weekStartsOn = 0) {
|
|
344
|
-
const time =
|
|
345
|
-
return (this.startOf(unit, weekStartsOn)
|
|
346
|
-
time.startOf(unit, weekStartsOn)
|
|
347
|
+
const time = _a.#cast(other);
|
|
348
|
+
return (this.startOf(unit, weekStartsOn).#timestamp >
|
|
349
|
+
time.startOf(unit, weekStartsOn).#timestamp);
|
|
347
350
|
}
|
|
348
351
|
isSameOrBefore(other, unit, weekStartsOn = 0) {
|
|
349
352
|
return (this.isSame(other, unit, weekStartsOn) || this.isBefore(other, unit, weekStartsOn));
|
|
@@ -510,7 +513,7 @@ class Chronos {
|
|
|
510
513
|
return this.#cloneStates(new _a(d), 'set');
|
|
511
514
|
}
|
|
512
515
|
diff(other, unit) {
|
|
513
|
-
const time =
|
|
516
|
+
const time = _a.#cast(other);
|
|
514
517
|
const msDiff = this.#date.getTime() - time.#date.getTime();
|
|
515
518
|
switch (unit) {
|
|
516
519
|
case 'millisecond':
|
|
@@ -828,10 +831,24 @@ class Chronos {
|
|
|
828
831
|
return result;
|
|
829
832
|
}
|
|
830
833
|
static min(...dates) {
|
|
831
|
-
|
|
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');
|
|
832
842
|
}
|
|
833
843
|
static max(...dates) {
|
|
834
|
-
|
|
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');
|
|
835
852
|
}
|
|
836
853
|
static isLeapYear(date) {
|
|
837
854
|
let year;
|
|
@@ -866,6 +883,9 @@ class Chronos {
|
|
|
866
883
|
static register(plugin) {
|
|
867
884
|
_a.use(plugin);
|
|
868
885
|
}
|
|
886
|
+
static #cast(date) {
|
|
887
|
+
return date instanceof _a ? date : new _a(date);
|
|
888
|
+
}
|
|
869
889
|
}
|
|
870
890
|
exports.Chronos = Chronos;
|
|
871
891
|
_a = Chronos;
|
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
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;
|
package/dist/esm/date/Chronos.js
CHANGED
|
@@ -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())) {
|
|
@@ -239,10 +242,10 @@ export class Chronos {
|
|
|
239
242
|
return (this.month + 1);
|
|
240
243
|
}
|
|
241
244
|
get unix() {
|
|
242
|
-
return Math.floor(this
|
|
245
|
+
return Math.floor(this.getTimeStamp() / 1000);
|
|
243
246
|
}
|
|
244
247
|
get timestamp() {
|
|
245
|
-
return this
|
|
248
|
+
return this.getTimeStamp();
|
|
246
249
|
}
|
|
247
250
|
get lastDateOfMonth() {
|
|
248
251
|
return this.daysInMonth();
|
|
@@ -280,7 +283,7 @@ export class Chronos {
|
|
|
280
283
|
return this.toUTC().toDate().toLocaleString(locales, options);
|
|
281
284
|
}
|
|
282
285
|
getTimeStamp() {
|
|
283
|
-
return this
|
|
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);
|
|
@@ -316,31 +319,31 @@ export class Chronos {
|
|
|
316
319
|
return isLeapYear(year ?? this.year);
|
|
317
320
|
}
|
|
318
321
|
isEqual(other) {
|
|
319
|
-
const time =
|
|
320
|
-
return this
|
|
322
|
+
const time = _a.#cast(other);
|
|
323
|
+
return this.#timestamp === time.#timestamp;
|
|
321
324
|
}
|
|
322
325
|
isEqualOrBefore(other) {
|
|
323
|
-
const time =
|
|
324
|
-
return this
|
|
326
|
+
const time = _a.#cast(other);
|
|
327
|
+
return this.#timestamp <= time.#timestamp;
|
|
325
328
|
}
|
|
326
329
|
isEqualOrAfter(other) {
|
|
327
|
-
const time =
|
|
328
|
-
return this
|
|
330
|
+
const time = _a.#cast(other);
|
|
331
|
+
return this.#timestamp >= time.#timestamp;
|
|
329
332
|
}
|
|
330
333
|
isSame(other, unit, weekStartsOn = 0) {
|
|
331
|
-
const time =
|
|
332
|
-
return (this.startOf(unit, weekStartsOn)
|
|
333
|
-
time.startOf(unit, weekStartsOn)
|
|
334
|
+
const time = _a.#cast(other);
|
|
335
|
+
return (this.startOf(unit, weekStartsOn).#timestamp ===
|
|
336
|
+
time.startOf(unit, weekStartsOn).#timestamp);
|
|
334
337
|
}
|
|
335
338
|
isBefore(other, unit, weekStartsOn = 0) {
|
|
336
|
-
const time =
|
|
337
|
-
return (this.startOf(unit, weekStartsOn)
|
|
338
|
-
time.startOf(unit, weekStartsOn)
|
|
339
|
+
const time = _a.#cast(other);
|
|
340
|
+
return (this.startOf(unit, weekStartsOn).#timestamp <
|
|
341
|
+
time.startOf(unit, weekStartsOn).#timestamp);
|
|
339
342
|
}
|
|
340
343
|
isAfter(other, unit, weekStartsOn = 0) {
|
|
341
|
-
const time =
|
|
342
|
-
return (this.startOf(unit, weekStartsOn)
|
|
343
|
-
time.startOf(unit, weekStartsOn)
|
|
344
|
+
const time = _a.#cast(other);
|
|
345
|
+
return (this.startOf(unit, weekStartsOn).#timestamp >
|
|
346
|
+
time.startOf(unit, weekStartsOn).#timestamp);
|
|
344
347
|
}
|
|
345
348
|
isSameOrBefore(other, unit, weekStartsOn = 0) {
|
|
346
349
|
return (this.isSame(other, unit, weekStartsOn) || this.isBefore(other, unit, weekStartsOn));
|
|
@@ -507,7 +510,7 @@ export class Chronos {
|
|
|
507
510
|
return this.#cloneStates(new _a(d), 'set');
|
|
508
511
|
}
|
|
509
512
|
diff(other, unit) {
|
|
510
|
-
const time =
|
|
513
|
+
const time = _a.#cast(other);
|
|
511
514
|
const msDiff = this.#date.getTime() - time.#date.getTime();
|
|
512
515
|
switch (unit) {
|
|
513
516
|
case 'millisecond':
|
|
@@ -825,10 +828,24 @@ export class Chronos {
|
|
|
825
828
|
return result;
|
|
826
829
|
}
|
|
827
830
|
static min(...dates) {
|
|
828
|
-
|
|
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');
|
|
829
839
|
}
|
|
830
840
|
static max(...dates) {
|
|
831
|
-
|
|
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');
|
|
832
849
|
}
|
|
833
850
|
static isLeapYear(date) {
|
|
834
851
|
let year;
|
|
@@ -863,6 +880,9 @@ export class Chronos {
|
|
|
863
880
|
static register(plugin) {
|
|
864
881
|
_a.use(plugin);
|
|
865
882
|
}
|
|
883
|
+
static #cast(date) {
|
|
884
|
+
return date instanceof _a ? date : new _a(date);
|
|
885
|
+
}
|
|
866
886
|
}
|
|
867
887
|
_a = Chronos;
|
|
868
888
|
export { chronos } from './chronos-fn.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nhb-toolbox",
|
|
3
|
-
"version": "4.26.
|
|
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",
|