nhb-toolbox 3.6.4 → 3.6.45
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 +16 -0
- package/dist/date/Chronos.d.ts.map +1 -1
- package/dist/date/Chronos.js +64 -0
- package/package.json +1 -1
package/dist/date/Chronos.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LocaleCode } from '../number/types';
|
|
1
2
|
import type { FormatOptions, TimeUnit, TimeZone, UTCOffSet } from './types';
|
|
2
3
|
export declare class Chronos {
|
|
3
4
|
#private;
|
|
@@ -28,6 +29,14 @@ export declare class Chronos {
|
|
|
28
29
|
toDate(): Date;
|
|
29
30
|
/** * Returns a string representation of a date. The format of the string depends on the locale. */
|
|
30
31
|
toString(): string;
|
|
32
|
+
/**
|
|
33
|
+
* * Wrapper over native `toLocaleString`
|
|
34
|
+
* @description Converts a date and time to a string by using the current or specified locale.
|
|
35
|
+
*
|
|
36
|
+
* @param locales A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
|
|
37
|
+
* @param options An object that contains one or more properties that specify comparison options.
|
|
38
|
+
*/
|
|
39
|
+
toLocaleString(locale?: LocaleCode | Intl.Locale | (LocaleCode | Intl.Locale)[], options?: Intl.DateTimeFormatOptions): string;
|
|
31
40
|
/** * Returns a date as a string value in ISO format. */
|
|
32
41
|
toISOString(): string;
|
|
33
42
|
/** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
|
|
@@ -248,5 +257,12 @@ export declare class Chronos {
|
|
|
248
257
|
* @param unit The unit to compare.
|
|
249
258
|
*/
|
|
250
259
|
isAfter(other: number | string | Date | Chronos, unit: TimeUnit): boolean;
|
|
260
|
+
/**
|
|
261
|
+
* * Returns a human-readable relative calendar time like "Today at 3:00 PM"
|
|
262
|
+
* @param baseDate Optional base date to compare with.
|
|
263
|
+
*/
|
|
264
|
+
calendar(baseDate?: number | string | Date | Chronos): string;
|
|
265
|
+
/** * Returns a short human-readable string like "2h ago", "in 5m" */
|
|
266
|
+
fromNowShort(): string;
|
|
251
267
|
}
|
|
252
268
|
//# sourceMappingURL=Chronos.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"
|
|
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,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,sEAAsE;IAC/D,KAAK,IAAI,OAAO;IAIvB,4EAA4E;IAC5E,MAAM,IAAI,MAAM;IAIhB,6EAA6E;IAC7E,OAAO,IAAI,MAAM;IAIjB,qDAAqD;IACrD,MAAM,IAAI,IAAI;IAId,mGAAmG;IACnG,QAAQ,IAAI,MAAM;IAIlB;;;;;;OAMG;IACH,cAAc,CACb,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,EAChE,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GAClC,MAAM;IAIT,wDAAwD;IACxD,WAAW,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AI,EAAE,QAAQ,GAAG,OAAO;IA8BnD;;;OAGG;IACI,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM;IAmBlC;;;;OAIG;IACI,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IA6BlD;;;;OAIG;IACI,IAAI,CACV,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,EACvC,IAAI,EAAE,QAAQ,GACZ,MAAM;IA0BT;;;;OAIG;IACI,MAAM,CACZ,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,EACvC,IAAI,EAAE,QAAQ,GACZ,OAAO;IASV;;;;OAIG;IACI,QAAQ,CACd,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,EACvC,IAAI,EAAE,QAAQ,GACZ,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;CAuBtB"}
|
package/dist/date/Chronos.js
CHANGED
|
@@ -51,6 +51,16 @@ export class Chronos {
|
|
|
51
51
|
toString() {
|
|
52
52
|
return this.#date.toString();
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* * Wrapper over native `toLocaleString`
|
|
56
|
+
* @description Converts a date and time to a string by using the current or specified locale.
|
|
57
|
+
*
|
|
58
|
+
* @param locales A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
|
|
59
|
+
* @param options An object that contains one or more properties that specify comparison options.
|
|
60
|
+
*/
|
|
61
|
+
toLocaleString(locale, options) {
|
|
62
|
+
return this.#date.toLocaleString(locale, options);
|
|
63
|
+
}
|
|
54
64
|
/** * Returns a date as a string value in ISO format. */
|
|
55
65
|
toISOString() {
|
|
56
66
|
return this.#date.toISOString();
|
|
@@ -685,4 +695,58 @@ export class Chronos {
|
|
|
685
695
|
return (this.startOf(unit).toDate().getTime() >
|
|
686
696
|
time.startOf(unit).toDate().getTime());
|
|
687
697
|
}
|
|
698
|
+
/**
|
|
699
|
+
* * Returns a human-readable relative calendar time like "Today at 3:00 PM"
|
|
700
|
+
* @param baseDate Optional base date to compare with.
|
|
701
|
+
*/
|
|
702
|
+
calendar(baseDate) {
|
|
703
|
+
const base = baseDate ? new Chronos(baseDate) : new Chronos();
|
|
704
|
+
const input = this.startOf('day');
|
|
705
|
+
const comparison = base.startOf('day');
|
|
706
|
+
const diff = input.diff(comparison, 'day');
|
|
707
|
+
const timeStr = this.toDate().toLocaleString(undefined, {
|
|
708
|
+
hour: 'numeric',
|
|
709
|
+
minute: '2-digit',
|
|
710
|
+
});
|
|
711
|
+
if (diff === 0)
|
|
712
|
+
return `Today at ${timeStr}`;
|
|
713
|
+
if (diff === 1)
|
|
714
|
+
return `Tomorrow at ${timeStr}`;
|
|
715
|
+
if (diff === -1)
|
|
716
|
+
return `Yesterday at ${timeStr}`;
|
|
717
|
+
return this.toDate().toLocaleString(undefined, {
|
|
718
|
+
month: 'long',
|
|
719
|
+
day: '2-digit',
|
|
720
|
+
year: 'numeric',
|
|
721
|
+
weekday: 'long',
|
|
722
|
+
hour: 'numeric',
|
|
723
|
+
minute: '2-digit',
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
/** * Returns a short human-readable string like "2h ago", "in 5m" */
|
|
727
|
+
fromNowShort() {
|
|
728
|
+
const now = new Chronos();
|
|
729
|
+
const diffInSeconds = this.diff(now, 'second');
|
|
730
|
+
const abs = Math.abs(diffInSeconds);
|
|
731
|
+
const suffix = diffInSeconds >= 0 ? 'in ' : '';
|
|
732
|
+
const postfix = diffInSeconds < 0 ? ' ago' : '';
|
|
733
|
+
if (abs < 60) {
|
|
734
|
+
return `${suffix}${Math.floor(abs)}s${postfix}`;
|
|
735
|
+
}
|
|
736
|
+
else if (abs < 3600) {
|
|
737
|
+
return `${suffix}${Math.floor(abs / 60)}m${postfix}`;
|
|
738
|
+
}
|
|
739
|
+
else if (abs < 86400) {
|
|
740
|
+
return `${suffix}${Math.floor(abs / 3600)}h${postfix}`;
|
|
741
|
+
}
|
|
742
|
+
else if (abs < 2592000) {
|
|
743
|
+
return `${suffix}${Math.floor(abs / 86400)}d${postfix}`;
|
|
744
|
+
}
|
|
745
|
+
else if (abs < 31536000) {
|
|
746
|
+
return `${suffix}${Math.floor(abs / 2592000)}mo${postfix}`;
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
return `${suffix}${Math.floor(abs / 31536000)}y${postfix}`;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
688
752
|
}
|
package/package.json
CHANGED