nhb-toolbox 3.6.45 → 3.6.50
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 +35 -3
- package/dist/date/Chronos.d.ts.map +1 -1
- package/dist/date/Chronos.js +92 -4
- package/package.json +1 -1
package/dist/date/Chronos.d.ts
CHANGED
|
@@ -41,10 +41,18 @@ export declare class Chronos {
|
|
|
41
41
|
toISOString(): string;
|
|
42
42
|
/** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
43
43
|
getTimeStamp(): number;
|
|
44
|
-
/** * Returns the date value as a `Date` object. */
|
|
45
|
-
get date(): Date;
|
|
46
44
|
/** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
47
45
|
get unix(): number;
|
|
46
|
+
get year(): number;
|
|
47
|
+
get month(): number;
|
|
48
|
+
get date(): number;
|
|
49
|
+
get day(): number;
|
|
50
|
+
get hour(): number;
|
|
51
|
+
get minute(): number;
|
|
52
|
+
get second(): number;
|
|
53
|
+
get millisecond(): number;
|
|
54
|
+
/** * ISO weekday: 1 = Monday, 7 = Sunday */
|
|
55
|
+
get isoWeekday(): number;
|
|
48
56
|
/**
|
|
49
57
|
* @instance Returns the current date and time in a specified format in local time.
|
|
50
58
|
* * Default format is dd, `MMM DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55:379`
|
|
@@ -210,7 +218,7 @@ export declare class Chronos {
|
|
|
210
218
|
* * Returns a new Chronos instance at the start of a given unit.
|
|
211
219
|
* @param unit The unit to reset (e.g., year, month, day).
|
|
212
220
|
*/
|
|
213
|
-
startOf(unit: TimeUnit): Chronos;
|
|
221
|
+
startOf(unit: TimeUnit | 'week'): Chronos;
|
|
214
222
|
/**
|
|
215
223
|
* * Returns a new Chronos instance at the end of a given unit.
|
|
216
224
|
* @param unit The unit to adjust (e.g., year, month, day).
|
|
@@ -264,5 +272,29 @@ export declare class Chronos {
|
|
|
264
272
|
calendar(baseDate?: number | string | Date | Chronos): string;
|
|
265
273
|
/** * Returns a short human-readable string like "2h ago", "in 5m" */
|
|
266
274
|
fromNowShort(): string;
|
|
275
|
+
/** * Returns ISO week number */
|
|
276
|
+
getWeek(): number;
|
|
277
|
+
/** * Returns ISO week year */
|
|
278
|
+
getWeekYear(): number;
|
|
279
|
+
/** * Returns day of year (1 - 366) */
|
|
280
|
+
getDayOfYear(): number;
|
|
281
|
+
/**
|
|
282
|
+
* * Checks if the current date is between the given start and end dates.
|
|
283
|
+
*
|
|
284
|
+
* @param start - The start of the range.
|
|
285
|
+
* @param end - The end of the range.
|
|
286
|
+
* @param inclusive - Specifies whether the comparison is inclusive or exclusive:
|
|
287
|
+
* - `'[]'`: inclusive of both start and end (≥ start and ≤ end)
|
|
288
|
+
* - `'[)'`: inclusive of start, exclusive of end (≥ start and < end)
|
|
289
|
+
* - `'(]'`: exclusive of start, inclusive of end (> start and ≤ end)
|
|
290
|
+
* - `'()'`: exclusive of both start and end (> start and < end)
|
|
291
|
+
*
|
|
292
|
+
* @returns `true` if the current date is within the specified range based on the `inclusive` mode.
|
|
293
|
+
*/
|
|
294
|
+
isBetween(start: number | string | Date | Chronos, end: number | string | Date | Chronos, inclusive?: '[]' | '[)' | '(]' | '()'): boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Returns number of days in current month
|
|
297
|
+
*/
|
|
298
|
+
daysInMonth(): number;
|
|
267
299
|
}
|
|
268
300
|
//# sourceMappingURL=Chronos.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,KAAK,EAEX,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,MAAM,SAAS,CAAC;AAGjB,qBAAa,OAAO;;IAInB;;;;;;;;OAQG;gBACS,KA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,OAAO;IASV;;;;OAIG;IACI,OAAO,CACb,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,EACvC,IAAI,EAAE,QAAQ,GACZ,OAAO;IASV;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM;IA0B7D,qEAAqE;IACrE,YAAY,IAAI,MAAM;IAwBtB,gCAAgC;IAChC,OAAO,IAAI,MAAM;IAcjB,8BAA8B;IAC9B,WAAW,IAAI,MAAM;IAKrB,sCAAsC;IACtC,YAAY,IAAI,MAAM;IAMtB;;;;;;;;;;;;OAYG;IACH,SAAS,CACR,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,EACvC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,EACrC,SAAS,GAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAW,GACzC,OAAO;IAiBV;;OAEG;IACH,WAAW,IAAI,MAAM;CAGrB"}
|
package/dist/date/Chronos.js
CHANGED
|
@@ -69,14 +69,39 @@ export class Chronos {
|
|
|
69
69
|
getTimeStamp() {
|
|
70
70
|
return this.#date.getTime();
|
|
71
71
|
}
|
|
72
|
-
/** * Returns the date value as a `Date` object. */
|
|
73
|
-
get date() {
|
|
74
|
-
return this.#date;
|
|
75
|
-
}
|
|
76
72
|
/** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
77
73
|
get unix() {
|
|
78
74
|
return this.#date.getTime();
|
|
79
75
|
}
|
|
76
|
+
get year() {
|
|
77
|
+
return this.#date.getFullYear();
|
|
78
|
+
}
|
|
79
|
+
get month() {
|
|
80
|
+
return this.#date.getMonth();
|
|
81
|
+
}
|
|
82
|
+
get date() {
|
|
83
|
+
return this.#date.getDate();
|
|
84
|
+
}
|
|
85
|
+
get day() {
|
|
86
|
+
return this.#date.getDay();
|
|
87
|
+
}
|
|
88
|
+
get hour() {
|
|
89
|
+
return this.#date.getHours();
|
|
90
|
+
}
|
|
91
|
+
get minute() {
|
|
92
|
+
return this.#date.getMinutes();
|
|
93
|
+
}
|
|
94
|
+
get second() {
|
|
95
|
+
return this.#date.getSeconds();
|
|
96
|
+
}
|
|
97
|
+
get millisecond() {
|
|
98
|
+
return this.#date.getMilliseconds();
|
|
99
|
+
}
|
|
100
|
+
/** * ISO weekday: 1 = Monday, 7 = Sunday */
|
|
101
|
+
get isoWeekday() {
|
|
102
|
+
const day = this.day;
|
|
103
|
+
return day === 0 ? 7 : day;
|
|
104
|
+
}
|
|
80
105
|
/**
|
|
81
106
|
* @instance Returns the current date and time in a specified format in local time.
|
|
82
107
|
* * Default format is dd, `MMM DD, YYYY HH:mm:ss` = `Sun, Apr 06, 2025 16:11:55:379`
|
|
@@ -529,6 +554,13 @@ export class Chronos {
|
|
|
529
554
|
d.setDate(1);
|
|
530
555
|
d.setHours(0, 0, 0, 0);
|
|
531
556
|
break;
|
|
557
|
+
case 'week': {
|
|
558
|
+
const day = d.getDay(); // 0 (Sun) - 6 (Sat)
|
|
559
|
+
const diff = (day + 6) % 7; // convert Sunday=0 to 6, Monday=1 to 0, etc.
|
|
560
|
+
d.setDate(d.getDate() - diff);
|
|
561
|
+
d.setHours(0, 0, 0, 0);
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
532
564
|
case 'day':
|
|
533
565
|
d.setHours(0, 0, 0, 0);
|
|
534
566
|
break;
|
|
@@ -749,4 +781,60 @@ export class Chronos {
|
|
|
749
781
|
return `${suffix}${Math.floor(abs / 31536000)}y${postfix}`;
|
|
750
782
|
}
|
|
751
783
|
}
|
|
784
|
+
/** * Returns ISO week number */
|
|
785
|
+
getWeek() {
|
|
786
|
+
// ISO week starts on Monday
|
|
787
|
+
const target = this.startOf('week').add(3, 'day');
|
|
788
|
+
const firstThursday = new Chronos(new Date(target.year, 0, 4))
|
|
789
|
+
.startOf('week')
|
|
790
|
+
.add(3, 'day');
|
|
791
|
+
const daysDiff = target.diff(firstThursday, 'day');
|
|
792
|
+
const week = Math.floor(daysDiff / 7) + 1;
|
|
793
|
+
return week;
|
|
794
|
+
}
|
|
795
|
+
/** * Returns ISO week year */
|
|
796
|
+
getWeekYear() {
|
|
797
|
+
const d = this.startOf('week').add(3, 'day'); // Thursday of current ISO week
|
|
798
|
+
return d.year;
|
|
799
|
+
}
|
|
800
|
+
/** * Returns day of year (1 - 366) */
|
|
801
|
+
getDayOfYear() {
|
|
802
|
+
const start = new Date(this.year, 0, 1);
|
|
803
|
+
const diff = this.#date.getTime() - start.getTime();
|
|
804
|
+
return Math.floor(diff / 86400000) + 1;
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* * Checks if the current date is between the given start and end dates.
|
|
808
|
+
*
|
|
809
|
+
* @param start - The start of the range.
|
|
810
|
+
* @param end - The end of the range.
|
|
811
|
+
* @param inclusive - Specifies whether the comparison is inclusive or exclusive:
|
|
812
|
+
* - `'[]'`: inclusive of both start and end (≥ start and ≤ end)
|
|
813
|
+
* - `'[)'`: inclusive of start, exclusive of end (≥ start and < end)
|
|
814
|
+
* - `'(]'`: exclusive of start, inclusive of end (> start and ≤ end)
|
|
815
|
+
* - `'()'`: exclusive of both start and end (> start and < end)
|
|
816
|
+
*
|
|
817
|
+
* @returns `true` if the current date is within the specified range based on the `inclusive` mode.
|
|
818
|
+
*/
|
|
819
|
+
isBetween(start, end, inclusive = '()') {
|
|
820
|
+
const s = new Chronos(start).valueOf();
|
|
821
|
+
const e = new Chronos(end).valueOf();
|
|
822
|
+
const t = this.valueOf();
|
|
823
|
+
switch (inclusive) {
|
|
824
|
+
case '[]':
|
|
825
|
+
return t >= s && t <= e;
|
|
826
|
+
case '[)':
|
|
827
|
+
return t >= s && t < e;
|
|
828
|
+
case '(]':
|
|
829
|
+
return t > s && t <= e;
|
|
830
|
+
case '()':
|
|
831
|
+
return t > s && t < e;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Returns number of days in current month
|
|
836
|
+
*/
|
|
837
|
+
daysInMonth() {
|
|
838
|
+
return new Date(this.year, this.month + 1, 0).getDate();
|
|
839
|
+
}
|
|
752
840
|
}
|
package/package.json
CHANGED