nhb-toolbox 3.6.3 → 3.6.4
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/dist/date/Chronos.d.ts +62 -9
- package/dist/date/Chronos.d.ts.map +1 -1
- package/dist/date/Chronos.js +185 -0
- package/dist/date/types.d.ts +2 -0
- package/dist/date/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/date/Chronos.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export declare class Chronos {
|
|
|
18
18
|
* @returns The primitive value based on the hint.
|
|
19
19
|
*/
|
|
20
20
|
[Symbol.toPrimitive](hint: string): string | number;
|
|
21
|
+
/** * Clones and returns a new Chronos instance with the same date. */
|
|
22
|
+
clone(): Chronos;
|
|
21
23
|
/** * Enables JSON.stringify and console logging to show readable output. */
|
|
22
24
|
toJSON(): string;
|
|
23
25
|
/** * Enables arithmetic and comparison operations (e.g., +new Chronos()). */
|
|
@@ -139,19 +141,19 @@ export declare class Chronos {
|
|
|
139
141
|
* @param time An optional time value to compare with (`string`, `number`, `Date`, or `Chronos` instance). Defaults to `now`.
|
|
140
142
|
* @returns The difference as a human-readable string, e.g., `2 years 1 month 9 days 18 hours 56 minutes ago`.
|
|
141
143
|
*/
|
|
142
|
-
fromNow(level?: Exclude<TimeUnit, 'millisecond'>, withSuffixPrefix?: boolean, time?:
|
|
144
|
+
fromNow(level?: Exclude<TimeUnit, 'millisecond'>, withSuffixPrefix?: boolean, time?: number | string | Date | Chronos): string;
|
|
143
145
|
/**
|
|
144
146
|
* * Returns the number of full years between the input date and now.
|
|
145
147
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
146
148
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
147
149
|
*/
|
|
148
|
-
getRelativeYear(time?:
|
|
150
|
+
getRelativeYear(time?: number | string | Date | Chronos): number;
|
|
149
151
|
/**
|
|
150
152
|
* * Returns the number of full months between the input date and now.
|
|
151
153
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
152
154
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
153
155
|
*/
|
|
154
|
-
getRelativeMonth(time?:
|
|
156
|
+
getRelativeMonth(time?: number | string | Date | Chronos): number;
|
|
155
157
|
/**
|
|
156
158
|
* * Determines if the given date is today, tomorrow, yesterday or any relative day.
|
|
157
159
|
* @param date - The date to compare (Date object).
|
|
@@ -162,31 +164,31 @@ export declare class Chronos {
|
|
|
162
164
|
* - `1` if the date is tomorrow.
|
|
163
165
|
* - Other positive or negative numbers for other relative days (e.g., `-2` for two days ago, `2` for two days ahead).
|
|
164
166
|
*/
|
|
165
|
-
getRelativeDay(time?:
|
|
167
|
+
getRelativeDay(time?: number | string | Date | Chronos): number;
|
|
166
168
|
/**
|
|
167
169
|
* * Returns the number of full hours between the input date and now.
|
|
168
170
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
169
171
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
170
172
|
*/
|
|
171
|
-
getRelativeHour(time?:
|
|
173
|
+
getRelativeHour(time?: number | string | Date | Chronos): number;
|
|
172
174
|
/**
|
|
173
175
|
* * Returns the number of full minutes between the input date and now.
|
|
174
176
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
175
177
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
176
178
|
*/
|
|
177
|
-
getRelativeMinute(time?:
|
|
179
|
+
getRelativeMinute(time?: number | string | Date | Chronos): number;
|
|
178
180
|
/**
|
|
179
181
|
* * Returns the number of full seconds between the input date and now.
|
|
180
182
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
181
183
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
182
184
|
*/
|
|
183
|
-
getRelativeSecond(time?:
|
|
185
|
+
getRelativeSecond(time?: number | string | Date | Chronos): number;
|
|
184
186
|
/**
|
|
185
187
|
* * Returns the number of milliseconds between the input date and now.
|
|
186
188
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
187
189
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
188
190
|
*/
|
|
189
|
-
getRelativeMilliSecond(time?:
|
|
191
|
+
getRelativeMilliSecond(time?: number | string | Date | Chronos): number;
|
|
190
192
|
/**
|
|
191
193
|
* * Compares the stored date with now, returning the difference in the specified unit.
|
|
192
194
|
*
|
|
@@ -194,6 +196,57 @@ export declare class Chronos {
|
|
|
194
196
|
* @param time Optional time to compare with the `Chronos` date/time.
|
|
195
197
|
* @returns The difference in number, negative is `Chronos` time is a past time else positive.
|
|
196
198
|
*/
|
|
197
|
-
compare(unit?: TimeUnit, time?:
|
|
199
|
+
compare(unit?: TimeUnit, time?: number | string | Date | Chronos): number;
|
|
200
|
+
/**
|
|
201
|
+
* * Returns a new Chronos instance at the start of a given unit.
|
|
202
|
+
* @param unit The unit to reset (e.g., year, month, day).
|
|
203
|
+
*/
|
|
204
|
+
startOf(unit: TimeUnit): Chronos;
|
|
205
|
+
/**
|
|
206
|
+
* * Returns a new Chronos instance at the end of a given unit.
|
|
207
|
+
* @param unit The unit to adjust (e.g., year, month, day).
|
|
208
|
+
*/
|
|
209
|
+
endOf(unit: TimeUnit): Chronos;
|
|
210
|
+
/**
|
|
211
|
+
* * Returns a new Chronos instance with the specified unit added.
|
|
212
|
+
* @param amount The amount to add (can be negative).
|
|
213
|
+
* @param unit The time unit to add.
|
|
214
|
+
*/
|
|
215
|
+
add(amount: number, unit: TimeUnit): Chronos;
|
|
216
|
+
/**
|
|
217
|
+
* * Gets the value of a specific time unit from the date.
|
|
218
|
+
* @param unit The unit to retrieve.
|
|
219
|
+
*/
|
|
220
|
+
get(unit: TimeUnit): number;
|
|
221
|
+
/**
|
|
222
|
+
* Returns a new Chronos instance with the specified unit set to the given value.
|
|
223
|
+
* @param unit The unit to modify.
|
|
224
|
+
* @param value The value to set for the unit.
|
|
225
|
+
*/
|
|
226
|
+
set(unit: TimeUnit, value: number): Chronos;
|
|
227
|
+
/**
|
|
228
|
+
* * Returns the difference between this and another date in the given unit.
|
|
229
|
+
* @param other The other date to compare.
|
|
230
|
+
* @param unit The unit in which to return the difference.
|
|
231
|
+
*/
|
|
232
|
+
diff(other: number | string | Date | Chronos, unit: TimeUnit): number;
|
|
233
|
+
/**
|
|
234
|
+
* * Checks if another date is the same as this one in a specific unit.
|
|
235
|
+
* @param other The other date to compare.
|
|
236
|
+
* @param unit The unit to compare.
|
|
237
|
+
*/
|
|
238
|
+
isSame(other: number | string | Date | Chronos, unit: TimeUnit): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* * Checks if this date is before another date in a specific unit.
|
|
241
|
+
* @param other The other date to compare.
|
|
242
|
+
* @param unit The unit to compare.
|
|
243
|
+
*/
|
|
244
|
+
isBefore(other: number | string | Date | Chronos, unit: TimeUnit): boolean;
|
|
245
|
+
/**
|
|
246
|
+
* * Checks if this date is after another date in a specific unit.
|
|
247
|
+
* @param other The other date to compare.
|
|
248
|
+
* @param unit The unit to compare.
|
|
249
|
+
*/
|
|
250
|
+
isAfter(other: number | string | Date | Chronos, unit: TimeUnit): boolean;
|
|
198
251
|
}
|
|
199
252
|
//# sourceMappingURL=Chronos.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEX,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,MAAM,SAAS,CAAC;AAGjB,qBAAa,OAAO;;IAInB;;;;;;;;OAQG;gBACS,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;IAOpD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAED;;;;OAIG;IACH,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAKnD,4EAA4E;IAC5E,MAAM,IAAI,MAAM;IAIh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,MAAM,GAAG,IAAI,GAAG,OAAO,EACvC,IAAI,EAAE,QAAQ,GACZ,OAAO;CAQV"}
|
package/dist/date/Chronos.js
CHANGED
|
@@ -31,6 +31,10 @@ export class Chronos {
|
|
|
31
31
|
return this.valueOf();
|
|
32
32
|
return this.toString();
|
|
33
33
|
}
|
|
34
|
+
/** * Clones and returns a new Chronos instance with the same date. */
|
|
35
|
+
clone() {
|
|
36
|
+
return new Chronos(this.#date);
|
|
37
|
+
}
|
|
34
38
|
/** * Enables JSON.stringify and console logging to show readable output. */
|
|
35
39
|
toJSON() {
|
|
36
40
|
return this.toISOString();
|
|
@@ -500,4 +504,185 @@ export class Chronos {
|
|
|
500
504
|
throw new Error(`Unsupported time unit: ${unit}`);
|
|
501
505
|
}
|
|
502
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* * Returns a new Chronos instance at the start of a given unit.
|
|
509
|
+
* @param unit The unit to reset (e.g., year, month, day).
|
|
510
|
+
*/
|
|
511
|
+
startOf(unit) {
|
|
512
|
+
const d = new Date(this.#date);
|
|
513
|
+
switch (unit) {
|
|
514
|
+
case 'year':
|
|
515
|
+
d.setMonth(0, 1);
|
|
516
|
+
d.setHours(0, 0, 0, 0);
|
|
517
|
+
break;
|
|
518
|
+
case 'month':
|
|
519
|
+
d.setDate(1);
|
|
520
|
+
d.setHours(0, 0, 0, 0);
|
|
521
|
+
break;
|
|
522
|
+
case 'day':
|
|
523
|
+
d.setHours(0, 0, 0, 0);
|
|
524
|
+
break;
|
|
525
|
+
case 'hour':
|
|
526
|
+
d.setMinutes(0, 0, 0);
|
|
527
|
+
break;
|
|
528
|
+
case 'minute':
|
|
529
|
+
d.setSeconds(0, 0);
|
|
530
|
+
break;
|
|
531
|
+
case 'second':
|
|
532
|
+
d.setMilliseconds(0);
|
|
533
|
+
break;
|
|
534
|
+
case 'millisecond':
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
return new Chronos(d);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* * Returns a new Chronos instance at the end of a given unit.
|
|
541
|
+
* @param unit The unit to adjust (e.g., year, month, day).
|
|
542
|
+
*/
|
|
543
|
+
endOf(unit) {
|
|
544
|
+
return this.startOf(unit).add(1, unit).add(-1, 'millisecond');
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* * Returns a new Chronos instance with the specified unit added.
|
|
548
|
+
* @param amount The amount to add (can be negative).
|
|
549
|
+
* @param unit The time unit to add.
|
|
550
|
+
*/
|
|
551
|
+
add(amount, unit) {
|
|
552
|
+
const d = new Date(this.#date);
|
|
553
|
+
switch (unit) {
|
|
554
|
+
case 'millisecond':
|
|
555
|
+
d.setMilliseconds(d.getMilliseconds() + amount);
|
|
556
|
+
break;
|
|
557
|
+
case 'second':
|
|
558
|
+
d.setSeconds(d.getSeconds() + amount);
|
|
559
|
+
break;
|
|
560
|
+
case 'minute':
|
|
561
|
+
d.setMinutes(d.getMinutes() + amount);
|
|
562
|
+
break;
|
|
563
|
+
case 'hour':
|
|
564
|
+
d.setHours(d.getHours() + amount);
|
|
565
|
+
break;
|
|
566
|
+
case 'day':
|
|
567
|
+
d.setDate(d.getDate() + amount);
|
|
568
|
+
break;
|
|
569
|
+
case 'month':
|
|
570
|
+
d.setMonth(d.getMonth() + amount);
|
|
571
|
+
break;
|
|
572
|
+
case 'year':
|
|
573
|
+
d.setFullYear(d.getFullYear() + amount);
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
return new Chronos(d);
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* * Gets the value of a specific time unit from the date.
|
|
580
|
+
* @param unit The unit to retrieve.
|
|
581
|
+
*/
|
|
582
|
+
get(unit) {
|
|
583
|
+
switch (unit) {
|
|
584
|
+
case 'year':
|
|
585
|
+
return this.#date.getFullYear();
|
|
586
|
+
case 'month':
|
|
587
|
+
return this.#date.getMonth();
|
|
588
|
+
case 'day':
|
|
589
|
+
return this.#date.getDate();
|
|
590
|
+
case 'hour':
|
|
591
|
+
return this.#date.getHours();
|
|
592
|
+
case 'minute':
|
|
593
|
+
return this.#date.getMinutes();
|
|
594
|
+
case 'second':
|
|
595
|
+
return this.#date.getSeconds();
|
|
596
|
+
case 'millisecond':
|
|
597
|
+
return this.#date.getMilliseconds();
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Returns a new Chronos instance with the specified unit set to the given value.
|
|
602
|
+
* @param unit The unit to modify.
|
|
603
|
+
* @param value The value to set for the unit.
|
|
604
|
+
*/
|
|
605
|
+
set(unit, value) {
|
|
606
|
+
const d = new Date(this.#date);
|
|
607
|
+
switch (unit) {
|
|
608
|
+
case 'year':
|
|
609
|
+
d.setFullYear(value);
|
|
610
|
+
break;
|
|
611
|
+
case 'month':
|
|
612
|
+
d.setMonth(value);
|
|
613
|
+
break;
|
|
614
|
+
case 'day':
|
|
615
|
+
d.setDate(value);
|
|
616
|
+
break;
|
|
617
|
+
case 'hour':
|
|
618
|
+
d.setHours(value);
|
|
619
|
+
break;
|
|
620
|
+
case 'minute':
|
|
621
|
+
d.setMinutes(value);
|
|
622
|
+
break;
|
|
623
|
+
case 'second':
|
|
624
|
+
d.setSeconds(value);
|
|
625
|
+
break;
|
|
626
|
+
case 'millisecond':
|
|
627
|
+
d.setMilliseconds(value);
|
|
628
|
+
break;
|
|
629
|
+
}
|
|
630
|
+
return new Chronos(d);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* * Returns the difference between this and another date in the given unit.
|
|
634
|
+
* @param other The other date to compare.
|
|
635
|
+
* @param unit The unit in which to return the difference.
|
|
636
|
+
*/
|
|
637
|
+
diff(other, unit) {
|
|
638
|
+
const time = new Chronos(other);
|
|
639
|
+
const msDiff = this.#date.getTime() - time.toDate().getTime();
|
|
640
|
+
switch (unit) {
|
|
641
|
+
case 'millisecond':
|
|
642
|
+
return msDiff;
|
|
643
|
+
case 'second':
|
|
644
|
+
return msDiff / 1e3;
|
|
645
|
+
case 'minute':
|
|
646
|
+
return msDiff / 6e4;
|
|
647
|
+
case 'hour':
|
|
648
|
+
return msDiff / 3.6e6;
|
|
649
|
+
case 'day':
|
|
650
|
+
return msDiff / 8.64e7;
|
|
651
|
+
case 'month':
|
|
652
|
+
return ((this.get('year') - time.get('year')) * 12 +
|
|
653
|
+
(this.get('month') - time.get('month')));
|
|
654
|
+
case 'year':
|
|
655
|
+
return this.get('year') - time.get('year');
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* * Checks if another date is the same as this one in a specific unit.
|
|
660
|
+
* @param other The other date to compare.
|
|
661
|
+
* @param unit The unit to compare.
|
|
662
|
+
*/
|
|
663
|
+
isSame(other, unit) {
|
|
664
|
+
const time = new Chronos(other);
|
|
665
|
+
return (this.startOf(unit).toDate().getTime() ===
|
|
666
|
+
time.startOf(unit).toDate().getTime());
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* * Checks if this date is before another date in a specific unit.
|
|
670
|
+
* @param other The other date to compare.
|
|
671
|
+
* @param unit The unit to compare.
|
|
672
|
+
*/
|
|
673
|
+
isBefore(other, unit) {
|
|
674
|
+
const time = new Chronos(other);
|
|
675
|
+
return (this.startOf(unit).toDate().getTime() <
|
|
676
|
+
time.startOf(unit).toDate().getTime());
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* * Checks if this date is after another date in a specific unit.
|
|
680
|
+
* @param other The other date to compare.
|
|
681
|
+
* @param unit The unit to compare.
|
|
682
|
+
*/
|
|
683
|
+
isAfter(other, unit) {
|
|
684
|
+
const time = new Chronos(other);
|
|
685
|
+
return (this.startOf(unit).toDate().getTime() >
|
|
686
|
+
time.startOf(unit).toDate().getTime());
|
|
687
|
+
}
|
|
503
688
|
}
|
package/dist/date/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Chronos } from './Chronos';
|
|
1
2
|
import type { DATE_FORMATS, DAY_FORMATS, HOUR_FORMATS, MILLISECOND_FORMATS, MINUTE_FORMATS, MONTH_FORMATS, SECOND_FORMATS, TIME_FORMATS, TIME_ZONES, YEAR_FORMATS } from './constants';
|
|
2
3
|
/** - Minute in numeric string from `00` to `23` */
|
|
3
4
|
export type Hours = '00' | '01' | '02' | '03' | '04' | '05' | '06' | '07' | '08' | '09' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23';
|
|
@@ -47,6 +48,7 @@ export type Second = (typeof SECOND_FORMATS)[number];
|
|
|
47
48
|
export type Millisecond = (typeof MILLISECOND_FORMATS)[number];
|
|
48
49
|
export type TimeFormats = (typeof TIME_FORMATS)[number];
|
|
49
50
|
export type ChronosFormat = Year | Month | Day | Date | Hour | Minute | Second | Millisecond | TimeFormats;
|
|
51
|
+
export type ChronosDate = number | string | Date | Chronos;
|
|
50
52
|
export type TimeZone = keyof typeof TIME_ZONES;
|
|
51
53
|
export type PositiveUTCHour = '+00' | '+01' | '+02' | '+03' | '+04' | '+05' | '+06' | '+07' | '+08' | '+09' | '+10' | '+11' | '+12' | '+13' | '+14';
|
|
52
54
|
export type NegativeUTCHour = '-00' | '-01' | '-02' | '-03' | '-04' | '-05' | '-06' | '-07' | '-08' | '-09' | '-10' | '-11' | '-12' | '-13' | '-14';
|
package/dist/date/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/date/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,cAAc,EACd,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,MAAM,aAAa,CAAC;AAErB,mDAAmD;AACnD,MAAM,MAAM,KAAK,GACd,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,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