@bbn/bbn 2.0.131 → 2.0.133
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/dt/classes/dt.d.ts
CHANGED
|
@@ -44,11 +44,11 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
44
44
|
compare(other: any, unit?: string): -1 | 0 | 1;
|
|
45
45
|
add(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
|
|
46
46
|
subtract(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
|
|
47
|
-
isBefore(other: any): boolean;
|
|
48
|
-
isBeforeOrSame(other: any): boolean;
|
|
49
|
-
isAfter(other: any): boolean;
|
|
50
|
-
isAfterOrSame(other: any): boolean;
|
|
51
|
-
isSame(other: any): boolean;
|
|
47
|
+
isBefore(other: any, unit?: string): boolean;
|
|
48
|
+
isBeforeOrSame(other: any, unit?: string): boolean;
|
|
49
|
+
isAfter(other: any, unit?: string): boolean;
|
|
50
|
+
isAfterOrSame(other: any, unit?: string): boolean;
|
|
51
|
+
isSame(other: any, unit?: string): boolean;
|
|
52
52
|
equals(other: any): boolean;
|
|
53
53
|
toJSON(): {
|
|
54
54
|
kind: bbnDtKind;
|
|
@@ -65,6 +65,8 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
65
65
|
date(v?: any): string | bbnDt<any>;
|
|
66
66
|
datetime(v?: any): string | bbnDt<any>;
|
|
67
67
|
time(v?: any): string | bbnDt<any>;
|
|
68
|
+
fdate(long?: boolean): string;
|
|
69
|
+
ftime(withSeconds?: boolean): string;
|
|
68
70
|
week(): number;
|
|
69
71
|
get YYYY(): string;
|
|
70
72
|
get YY(): string;
|
|
@@ -89,6 +91,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
89
91
|
get W(): string;
|
|
90
92
|
unix(ms?: boolean | number): number | bbnDt<any>;
|
|
91
93
|
format(format?: string): string;
|
|
94
|
+
calendar(short?: boolean): string;
|
|
92
95
|
matchFormat(value: any, format: string): boolean;
|
|
93
96
|
getWeekday(n: 0 | 1 | 2 | 3 | 4 | 5 | 6, mode?: string, locale?: string): string | object;
|
|
94
97
|
getWeekdayIndex: (name: string, locale?: string) => number;
|
package/dist/dt/classes/dt.js
CHANGED
|
@@ -304,20 +304,20 @@ export class bbnDt {
|
|
|
304
304
|
return new this.constructor(d);
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
|
-
isBefore(other) {
|
|
308
|
-
return this.compare(other) < 0;
|
|
307
|
+
isBefore(other, unit) {
|
|
308
|
+
return this.compare(other, unit) < 0;
|
|
309
309
|
}
|
|
310
|
-
isBeforeOrSame(other) {
|
|
311
|
-
return this.compare(other) <= 0;
|
|
310
|
+
isBeforeOrSame(other, unit) {
|
|
311
|
+
return this.compare(other, unit) <= 0;
|
|
312
312
|
}
|
|
313
|
-
isAfter(other) {
|
|
314
|
-
return this.compare(other) > 0;
|
|
313
|
+
isAfter(other, unit) {
|
|
314
|
+
return this.compare(other, unit) > 0;
|
|
315
315
|
}
|
|
316
|
-
isAfterOrSame(other) {
|
|
317
|
-
return this.compare(other) >= 0;
|
|
316
|
+
isAfterOrSame(other, unit) {
|
|
317
|
+
return this.compare(other, unit) >= 0;
|
|
318
318
|
}
|
|
319
|
-
isSame(other) {
|
|
320
|
-
return this.compare(other) === 0;
|
|
319
|
+
isSame(other, unit) {
|
|
320
|
+
return this.compare(other, unit) === 0;
|
|
321
321
|
}
|
|
322
322
|
equals(other) {
|
|
323
323
|
return this.isSame(other);
|
|
@@ -464,6 +464,18 @@ export class bbnDt {
|
|
|
464
464
|
}
|
|
465
465
|
return this.HH + ':' + this.II + ':' + this.SS;
|
|
466
466
|
}
|
|
467
|
+
fdate(long = false) {
|
|
468
|
+
if (!this.value) {
|
|
469
|
+
return '';
|
|
470
|
+
}
|
|
471
|
+
return bbn.dt.locales.formatters.short.format(new Date(this.toEpochMs()));
|
|
472
|
+
}
|
|
473
|
+
ftime(withSeconds = true) {
|
|
474
|
+
if (!this.value) {
|
|
475
|
+
return '';
|
|
476
|
+
}
|
|
477
|
+
return this.format('HH:II' + (withSeconds ? ':SS' : ''));
|
|
478
|
+
}
|
|
467
479
|
week() {
|
|
468
480
|
if (!this.value) {
|
|
469
481
|
return undefined;
|
|
@@ -669,6 +681,22 @@ export class bbnDt {
|
|
|
669
681
|
}
|
|
670
682
|
return str;
|
|
671
683
|
}
|
|
684
|
+
calendar(short) {
|
|
685
|
+
const now = this.constructor.now();
|
|
686
|
+
const startThis = this.startOf("day");
|
|
687
|
+
const startNow = now.startOf("day");
|
|
688
|
+
const diffDays = startThis.diff(startNow, "day");
|
|
689
|
+
const rtf = new Intl.RelativeTimeFormat(bbn.env.lang, { numeric: "auto" });
|
|
690
|
+
let phrase;
|
|
691
|
+
if (diffDays >= -6 && diffDays <= 6) {
|
|
692
|
+
phrase = rtf.format(diffDays, "day");
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
const diffWeeks = Math.floor(diffDays / 7);
|
|
696
|
+
phrase = rtf.format(diffWeeks, "week");
|
|
697
|
+
}
|
|
698
|
+
return `${phrase} ${this.ftime()}`;
|
|
699
|
+
}
|
|
672
700
|
matchFormat(value, format) {
|
|
673
701
|
try {
|
|
674
702
|
this.parse(value, format);
|
|
@@ -233,6 +233,9 @@ const buildLocaleFromIntl = () => {
|
|
|
233
233
|
const fmtMonthShort = new Intl.DateTimeFormat(langs, { month: 'short' });
|
|
234
234
|
const fmtWeekLong = new Intl.DateTimeFormat(langs, { weekday: 'long' });
|
|
235
235
|
const fmtWeekShort = new Intl.DateTimeFormat(langs, { weekday: 'short' });
|
|
236
|
+
const fmtShort = new Intl.DateTimeFormat(langs, { dateStyle: 'short', timeStyle: 'short' });
|
|
237
|
+
const fmtLong = new Intl.DateTimeFormat(langs, { dateStyle: 'long', timeStyle: 'long' });
|
|
238
|
+
const rtf = new Intl.RelativeTimeFormat(langs, { numeric: 'auto' });
|
|
236
239
|
// Create 12 dates for months (2020 chosen arbitrarily)
|
|
237
240
|
const monthsLong = [];
|
|
238
241
|
const monthsShort = [];
|
|
@@ -253,6 +256,11 @@ const buildLocaleFromIntl = () => {
|
|
|
253
256
|
}
|
|
254
257
|
const { date, time, datetime } = getCommonFormatsForLocale(langs);
|
|
255
258
|
extend(bbn.dt.locales, {
|
|
259
|
+
formatters: {
|
|
260
|
+
short: fmtShort,
|
|
261
|
+
long: fmtLong,
|
|
262
|
+
relative: rtf
|
|
263
|
+
},
|
|
256
264
|
monthsLong,
|
|
257
265
|
monthsShort,
|
|
258
266
|
weekdaysLong,
|