nhb-toolbox 3.7.5 → 3.7.7
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 +18 -16
- package/dist/date/Chronos.d.ts.map +1 -1
- package/dist/date/Chronos.js +93 -62
- package/dist/date/types.d.ts +12 -0
- package/dist/date/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/date/Chronos.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { LocaleCode } from '../number/types';
|
|
2
|
-
import type { FormatOptions, TimeUnit, TimeZone, UTCOffSet } from './types';
|
|
2
|
+
import type { ChronosObject, FormatOptions, TimeUnit, TimeZone, UTCOffSet } from './types';
|
|
3
|
+
declare const ORIGIN: unique symbol;
|
|
3
4
|
export declare class Chronos {
|
|
4
5
|
#private;
|
|
6
|
+
[ORIGIN]?: string;
|
|
5
7
|
/**
|
|
6
8
|
* * Creates a new immutable `Chronos` instance.
|
|
7
9
|
*
|
|
@@ -12,6 +14,7 @@ export declare class Chronos {
|
|
|
12
14
|
* - If a Chronos object is provided, it will be converted to a Date object.
|
|
13
15
|
*/
|
|
14
16
|
constructor(value?: number | string | Date | Chronos);
|
|
17
|
+
[Symbol.iterator](): IterableIterator<[string, number]>;
|
|
15
18
|
get [Symbol.toStringTag](): string;
|
|
16
19
|
/**
|
|
17
20
|
* * Enables primitive coercion like `console.log`, `${chronos}`, etc.
|
|
@@ -19,6 +22,8 @@ export declare class Chronos {
|
|
|
19
22
|
* @returns The primitive value based on the hint.
|
|
20
23
|
*/
|
|
21
24
|
[Symbol.toPrimitive](hint: string): string | number;
|
|
25
|
+
/** Returns a debug-friendly string for console.log or util.inspect */
|
|
26
|
+
inspect(): string;
|
|
22
27
|
/** * Clones and returns a new Chronos instance with the same date. */
|
|
23
28
|
clone(): Chronos;
|
|
24
29
|
/** * Enables JSON.stringify and console logging to show readable output. */
|
|
@@ -31,6 +36,8 @@ export declare class Chronos {
|
|
|
31
36
|
toString(): string;
|
|
32
37
|
/** * Returns ISO string with local time zone offset */
|
|
33
38
|
toLocalISOString(): string;
|
|
39
|
+
/** * Returns a date as a string value in ISO format. */
|
|
40
|
+
toISOString(): string;
|
|
34
41
|
/**
|
|
35
42
|
* * Wrapper over native `toLocaleString`
|
|
36
43
|
* @description Converts a date and time to a string by using the current or specified locale.
|
|
@@ -39,8 +46,6 @@ export declare class Chronos {
|
|
|
39
46
|
* @param options An object that contains one or more properties that specify comparison options.
|
|
40
47
|
*/
|
|
41
48
|
toLocaleString(locale?: LocaleCode | Intl.Locale | (LocaleCode | Intl.Locale)[], options?: Intl.DateTimeFormatOptions): string;
|
|
42
|
-
/** * Returns a date as a string value in ISO format. */
|
|
43
|
-
toISOString(): string;
|
|
44
49
|
/** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
45
50
|
getTimeStamp(): number;
|
|
46
51
|
/** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
@@ -297,28 +302,24 @@ export declare class Chronos {
|
|
|
297
302
|
/** * Returns number of days in current month */
|
|
298
303
|
daysInMonth(): number;
|
|
299
304
|
/** * Converts to object with all date unit parts */
|
|
300
|
-
toObject():
|
|
301
|
-
year: number;
|
|
302
|
-
month: number;
|
|
303
|
-
isoMonth: number;
|
|
304
|
-
date: number;
|
|
305
|
-
day: number;
|
|
306
|
-
isoDay: number;
|
|
307
|
-
hour: number;
|
|
308
|
-
minute: number;
|
|
309
|
-
second: number;
|
|
310
|
-
millisecond: number;
|
|
311
|
-
};
|
|
305
|
+
toObject(): ChronosObject;
|
|
312
306
|
/** * Converts to array with all date unit parts */
|
|
313
|
-
toArray(): [
|
|
307
|
+
toArray(): any[];
|
|
314
308
|
/** * Returns offset like +06:00 */
|
|
315
309
|
getUTCOffset(): string;
|
|
316
310
|
/** * Checks if currently in DST */
|
|
317
311
|
isDST(): boolean;
|
|
318
312
|
/** * Returns new Chronos instance in UTC */
|
|
313
|
+
toUTC(): Chronos;
|
|
319
314
|
/** * Returns new Chronos instance in local time */
|
|
315
|
+
toLocal(): Chronos;
|
|
320
316
|
/** @static Parses a date string with a given format (partial support) */
|
|
321
317
|
static parse(dateStr: string, format: string): Chronos;
|
|
318
|
+
/**
|
|
319
|
+
* @static Creates UTC Chronos
|
|
320
|
+
* @param dateLike Date input to create utc time.
|
|
321
|
+
*/
|
|
322
|
+
static utc(dateLike: number | string | Date | Chronos): Chronos;
|
|
322
323
|
/**
|
|
323
324
|
* @static Returns earliest Chronos
|
|
324
325
|
* @param dates Date inputs.
|
|
@@ -330,4 +331,5 @@ export declare class Chronos {
|
|
|
330
331
|
*/
|
|
331
332
|
static max(...dates: (number | string | Date | Chronos)[]): Chronos;
|
|
332
333
|
}
|
|
334
|
+
export {};
|
|
333
335
|
//# 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;;
|
|
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,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,MAAM,SAAS,CAAC;AAGjB,QAAA,MAAM,MAAM,eAAmB,CAAC;AAEhC,qBAAa,OAAO;;IAEnB,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;;;;OAQG;gBACS,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;I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AMhB,mDAAmD;IACnD,OAAO,IAAI,OAAO;IAMlB,yEAAyE;IACzE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IA6CtD;;;OAGG;IACH,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,GAAG,OAAO;IAM/D;;;OAGG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,EAAE,GAAG,OAAO;IAMnE;;;OAGG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,EAAE,GAAG,OAAO;CAKnE"}
|
package/dist/date/Chronos.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DAYS, MONTHS, sortedFormats, TIME_ZONES } from './constants';
|
|
2
2
|
import { isValidUTCOffSet } from './guards';
|
|
3
3
|
import { extractMinutesFromUTC } from './utils';
|
|
4
|
+
const ORIGIN = Symbol('origin');
|
|
4
5
|
export class Chronos {
|
|
5
6
|
#date;
|
|
6
|
-
|
|
7
|
+
[ORIGIN];
|
|
7
8
|
/**
|
|
8
9
|
* * Creates a new immutable `Chronos` instance.
|
|
9
10
|
*
|
|
@@ -16,10 +17,33 @@ export class Chronos {
|
|
|
16
17
|
constructor(value) {
|
|
17
18
|
const date = this.#toNewDate(value);
|
|
18
19
|
this.#date = date;
|
|
19
|
-
|
|
20
|
+
this[ORIGIN] = 'root';
|
|
21
|
+
}
|
|
22
|
+
*[Symbol.iterator]() {
|
|
23
|
+
yield ['year', this.year];
|
|
24
|
+
yield ['month', this.month];
|
|
25
|
+
yield ['isoMonth', this.month + 1];
|
|
26
|
+
yield ['date', this.date];
|
|
27
|
+
yield ['day', this.day];
|
|
28
|
+
yield ['isoDay', this.day + 1];
|
|
29
|
+
yield ['hour', this.hour];
|
|
30
|
+
yield ['minute', this.minute];
|
|
31
|
+
yield ['second', this.second];
|
|
32
|
+
yield ['millisecond', this.millisecond];
|
|
33
|
+
}
|
|
34
|
+
#withOrigin(origin) {
|
|
35
|
+
const instance = new Chronos(this.#date);
|
|
36
|
+
instance[ORIGIN] = origin;
|
|
37
|
+
return instance;
|
|
20
38
|
}
|
|
21
39
|
get [Symbol.toStringTag]() {
|
|
22
|
-
|
|
40
|
+
switch (this[ORIGIN]) {
|
|
41
|
+
case 'toUTC':
|
|
42
|
+
case 'utc':
|
|
43
|
+
return this.#toLocalISOString().replace(this.getUTCOffset(), 'Z');
|
|
44
|
+
default:
|
|
45
|
+
return this.#toLocalISOString();
|
|
46
|
+
}
|
|
23
47
|
}
|
|
24
48
|
/**
|
|
25
49
|
* * Enables primitive coercion like `console.log`, `${chronos}`, etc.
|
|
@@ -31,6 +55,10 @@ export class Chronos {
|
|
|
31
55
|
return this.valueOf();
|
|
32
56
|
return this.toLocalISOString();
|
|
33
57
|
}
|
|
58
|
+
/** Returns a debug-friendly string for console.log or util.inspect */
|
|
59
|
+
inspect() {
|
|
60
|
+
return `[Chronos ${this.toLocalISOString()}]`;
|
|
61
|
+
}
|
|
34
62
|
/** * Clones and returns a new Chronos instance with the same date. */
|
|
35
63
|
clone() {
|
|
36
64
|
return new Chronos(this.#date);
|
|
@@ -49,13 +77,45 @@ export class Chronos {
|
|
|
49
77
|
}
|
|
50
78
|
/** * Returns a string representation of a date. The format of the string depends on the locale. */
|
|
51
79
|
toString() {
|
|
52
|
-
|
|
80
|
+
switch (this[ORIGIN]) {
|
|
81
|
+
case 'toUTC':
|
|
82
|
+
case 'utc': {
|
|
83
|
+
const mins = extractMinutesFromUTC(`UTC${this.getUTCOffset()}`);
|
|
84
|
+
const date = this.addMinutes(mins);
|
|
85
|
+
return date.toString();
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
return this.#date.toString();
|
|
89
|
+
}
|
|
53
90
|
}
|
|
54
91
|
/** * Returns ISO string with local time zone offset */
|
|
55
|
-
toLocalISOString() {
|
|
92
|
+
#toLocalISOString() {
|
|
56
93
|
const pad = (n, p = 2) => String(n).padStart(p, '0');
|
|
57
94
|
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.getUTCOffset()}`;
|
|
58
95
|
}
|
|
96
|
+
/** * Returns ISO string with local time zone offset */
|
|
97
|
+
toLocalISOString() {
|
|
98
|
+
switch (this[ORIGIN]) {
|
|
99
|
+
case 'toUTC':
|
|
100
|
+
case 'utc': {
|
|
101
|
+
const mins = extractMinutesFromUTC(`UTC${this.getUTCOffset()}`);
|
|
102
|
+
const date = this.addMinutes(mins);
|
|
103
|
+
return date.#toLocalISOString();
|
|
104
|
+
}
|
|
105
|
+
default:
|
|
106
|
+
return this.#toLocalISOString();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** * Returns a date as a string value in ISO format. */
|
|
110
|
+
toISOString() {
|
|
111
|
+
switch (this[ORIGIN]) {
|
|
112
|
+
case 'toUTC':
|
|
113
|
+
case 'utc':
|
|
114
|
+
return this.#toLocalISOString().replace(this.getUTCOffset(), 'Z');
|
|
115
|
+
default:
|
|
116
|
+
return this.#date.toISOString();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
59
119
|
/**
|
|
60
120
|
* * Wrapper over native `toLocaleString`
|
|
61
121
|
* @description Converts a date and time to a string by using the current or specified locale.
|
|
@@ -66,10 +126,6 @@ export class Chronos {
|
|
|
66
126
|
toLocaleString(locale, options) {
|
|
67
127
|
return this.#date.toLocaleString(locale, options);
|
|
68
128
|
}
|
|
69
|
-
/** * Returns a date as a string value in ISO format. */
|
|
70
|
-
toISOString() {
|
|
71
|
-
return this.#date.toISOString();
|
|
72
|
-
}
|
|
73
129
|
/** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
74
130
|
getTimeStamp() {
|
|
75
131
|
return this.#date.getTime();
|
|
@@ -237,7 +293,13 @@ export class Chronos {
|
|
|
237
293
|
* @returns Formatted date string in desired format (UTC time).
|
|
238
294
|
*/
|
|
239
295
|
formatUTC(format = 'dd, MMM DD, YYYY HH:mm:ss:mss') {
|
|
240
|
-
|
|
296
|
+
switch (this[ORIGIN]) {
|
|
297
|
+
case 'toUTC':
|
|
298
|
+
case 'utc':
|
|
299
|
+
return this.#format(format, false);
|
|
300
|
+
default:
|
|
301
|
+
return this.#format(format, true);
|
|
302
|
+
}
|
|
241
303
|
}
|
|
242
304
|
/**
|
|
243
305
|
* * Adds seconds and returns a new immutable instance.
|
|
@@ -842,30 +904,11 @@ export class Chronos {
|
|
|
842
904
|
}
|
|
843
905
|
/** * Converts to object with all date unit parts */
|
|
844
906
|
toObject() {
|
|
845
|
-
return
|
|
846
|
-
year: this.year,
|
|
847
|
-
month: this.month,
|
|
848
|
-
isoMonth: this.month + 1,
|
|
849
|
-
date: this.date,
|
|
850
|
-
day: this.day,
|
|
851
|
-
isoDay: this.day + 1,
|
|
852
|
-
hour: this.hour,
|
|
853
|
-
minute: this.minute,
|
|
854
|
-
second: this.second,
|
|
855
|
-
millisecond: this.millisecond,
|
|
856
|
-
};
|
|
907
|
+
return Object.fromEntries([...this]);
|
|
857
908
|
}
|
|
858
909
|
/** * Converts to array with all date unit parts */
|
|
859
910
|
toArray() {
|
|
860
|
-
return
|
|
861
|
-
this.year,
|
|
862
|
-
this.month,
|
|
863
|
-
this.date,
|
|
864
|
-
this.hour,
|
|
865
|
-
this.minute,
|
|
866
|
-
this.second,
|
|
867
|
-
this.millisecond,
|
|
868
|
-
];
|
|
911
|
+
return Object.values(this.toObject());
|
|
869
912
|
}
|
|
870
913
|
/** * Returns offset like +06:00 */
|
|
871
914
|
getUTCOffset() {
|
|
@@ -882,29 +925,17 @@ export class Chronos {
|
|
|
882
925
|
this.#date.getTimezoneOffset());
|
|
883
926
|
}
|
|
884
927
|
/** * Returns new Chronos instance in UTC */
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
// // this.#date.getDate(),
|
|
891
|
-
// // this.#date.getHours(),
|
|
892
|
-
// // this.#date.getMinutes(),
|
|
893
|
-
// // this.#date.getSeconds(),
|
|
894
|
-
// // this.#date.getMilliseconds(),
|
|
895
|
-
// // ),
|
|
896
|
-
// // );
|
|
897
|
-
// // return new Chronos(utcDate);
|
|
898
|
-
// const date = this.#date;
|
|
899
|
-
// const utc = new Date(date.getTime() + date.getTimezoneOffset() * 60000);
|
|
900
|
-
// return new Chronos(utc);
|
|
901
|
-
// }
|
|
928
|
+
toUTC() {
|
|
929
|
+
const date = this.#date;
|
|
930
|
+
const utc = new Date(date.getTime() + date.getTimezoneOffset() * 60000);
|
|
931
|
+
return new Chronos(utc).#withOrigin('toUTC');
|
|
932
|
+
}
|
|
902
933
|
/** * Returns new Chronos instance in local time */
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
934
|
+
toLocal() {
|
|
935
|
+
const date = this.#date;
|
|
936
|
+
const utc = new Date(date.getTime() - date.getTimezoneOffset() * 60000);
|
|
937
|
+
return new Chronos(utc).#withOrigin('toLocal');
|
|
938
|
+
}
|
|
908
939
|
/** @static Parses a date string with a given format (partial support) */
|
|
909
940
|
static parse(dateStr, format) {
|
|
910
941
|
const formatMap = {
|
|
@@ -931,15 +962,15 @@ export class Chronos {
|
|
|
931
962
|
}, {});
|
|
932
963
|
return new Chronos(new Date(values.year ?? 1970, (values.month ?? 1) - 1, values.date ?? 1, values.hour ?? 0, values.minute ?? 0, values.second ?? 0));
|
|
933
964
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
965
|
+
/**
|
|
966
|
+
* @static Creates UTC Chronos
|
|
967
|
+
* @param dateLike Date input to create utc time.
|
|
968
|
+
*/
|
|
969
|
+
static utc(dateLike) {
|
|
970
|
+
const date = new Chronos(dateLike).#date;
|
|
971
|
+
const utc = new Date(date.getTime() + date.getTimezoneOffset() * 60000);
|
|
972
|
+
return new Chronos(utc).#withOrigin('utc');
|
|
973
|
+
}
|
|
943
974
|
/**
|
|
944
975
|
* @static Returns earliest Chronos
|
|
945
976
|
* @param dates Date inputs.
|
package/dist/date/types.d.ts
CHANGED
|
@@ -49,6 +49,18 @@ export type Millisecond = (typeof MILLISECOND_FORMATS)[number];
|
|
|
49
49
|
export type TimeFormats = (typeof TIME_FORMATS)[number];
|
|
50
50
|
export type ChronosFormat = Year | Month | Day | Date | Hour | Minute | Second | Millisecond | TimeFormats;
|
|
51
51
|
export type ChronosDate = number | string | Date | Chronos;
|
|
52
|
+
export interface ChronosObject {
|
|
53
|
+
year: number;
|
|
54
|
+
month: number;
|
|
55
|
+
isoMonth: number;
|
|
56
|
+
date: number;
|
|
57
|
+
day: number;
|
|
58
|
+
isoDay: number;
|
|
59
|
+
hour: number;
|
|
60
|
+
minute: number;
|
|
61
|
+
second: number;
|
|
62
|
+
millisecond: number;
|
|
63
|
+
}
|
|
52
64
|
export type TimeZone = keyof typeof TIME_ZONES;
|
|
53
65
|
export type PositiveUTCHour = '+00' | '+01' | '+02' | '+03' | '+04' | '+05' | '+06' | '+07' | '+08' | '+09' | '+10' | '+11' | '+12' | '+13' | '+14';
|
|
54
66
|
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,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EACX,YAAY,EACZ,WAAW,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