@bbn/bbn 2.0.154 → 2.0.156
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/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/dt/classes/dt.d.ts +2 -1
- package/dist/dt/classes/dt.js +29 -14
- package/package.json +1 -1
package/dist/dt/classes/dt.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
46
46
|
compare(other: any, unit?: string): -1 | 0 | 1;
|
|
47
47
|
add(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
|
|
48
48
|
subtract(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
|
|
49
|
+
duration(amount: number, unit: string): bbnDtDuration;
|
|
49
50
|
isBefore(other: any, unit?: string): boolean;
|
|
50
51
|
isBeforeOrSame(other: any, unit?: string): boolean;
|
|
51
52
|
isAfter(other: any, unit?: string): boolean;
|
|
@@ -97,7 +98,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
97
98
|
format(format?: string): string;
|
|
98
99
|
calendar(short?: boolean): string;
|
|
99
100
|
matchFormat(value: any, format: string): boolean;
|
|
100
|
-
getWeekday(n:
|
|
101
|
+
getWeekday(n: number, mode?: string, locale?: string): string | object;
|
|
101
102
|
getWeekdayIndex: (name: string, locale?: string) => number;
|
|
102
103
|
/**
|
|
103
104
|
* Returns a NEW date that is the next (or previous if past=true)
|
package/dist/dt/classes/dt.js
CHANGED
|
@@ -325,6 +325,9 @@ export class bbnDt {
|
|
|
325
325
|
return new this.constructor(d);
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
|
+
duration(amount, unit) {
|
|
329
|
+
return bbnDtDuration.fromUnit(amount, unit);
|
|
330
|
+
}
|
|
328
331
|
isBefore(other, unit) {
|
|
329
332
|
return this.compare(other, unit) < 0;
|
|
330
333
|
}
|
|
@@ -560,8 +563,8 @@ export class bbnDt {
|
|
|
560
563
|
const diffDays = Math.floor((d.getTime() - jan1.getTime()) / MS_PER_DAY); // 0 for Jan 1
|
|
561
564
|
const jan1Dow = jan1.getUTCDay(); // 0–6, Sunday=0
|
|
562
565
|
// How many days long is week 1?
|
|
563
|
-
// Week 1 starts on Jan 1 and ends the day before the first `
|
|
564
|
-
let offset = (bbn.dt.locales.
|
|
566
|
+
// Week 1 starts on Jan 1 and ends the day before the first `firstDayOfWeek` after Jan 1.
|
|
567
|
+
let offset = (bbn.dt.locales.firstDayOfWeek - jan1Dow + 7) % 7;
|
|
565
568
|
const firstWeekLength = offset === 0 ? 7 : offset;
|
|
566
569
|
// Still in the first (possibly partial) week
|
|
567
570
|
if (diffDays < firstWeekLength) {
|
|
@@ -630,13 +633,13 @@ export class bbnDt {
|
|
|
630
633
|
}
|
|
631
634
|
get dddd() {
|
|
632
635
|
if ('dayOfWeek' in this.value) {
|
|
633
|
-
return this.getWeekday(
|
|
636
|
+
return this.getWeekday(this.value.dayOfWeek, 'long');
|
|
634
637
|
}
|
|
635
638
|
return undefined;
|
|
636
639
|
}
|
|
637
640
|
get ddd() {
|
|
638
|
-
if ('
|
|
639
|
-
return this.getWeekday(
|
|
641
|
+
if ('dayOfWeek' in this.value) {
|
|
642
|
+
return this.getWeekday(this.value.dayOfWeek, 'short');
|
|
640
643
|
}
|
|
641
644
|
return undefined;
|
|
642
645
|
}
|
|
@@ -797,19 +800,32 @@ export class bbnDt {
|
|
|
797
800
|
const startThis = this.startOf("day");
|
|
798
801
|
const startNow = now.startOf("day");
|
|
799
802
|
const diffDays = startThis.diff(startNow, "day");
|
|
800
|
-
const
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
phrase = rtf.format(diffDays, "day");
|
|
803
|
+
const options = { numeric: "auto" };
|
|
804
|
+
if (short) {
|
|
805
|
+
options.style = "short";
|
|
804
806
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
807
|
+
const rtf = new Intl.RelativeTimeFormat(bbn.env.lang, options);
|
|
808
|
+
let phrase = '';
|
|
809
|
+
let parts = [];
|
|
810
|
+
let prefix = '';
|
|
811
|
+
if ((diffDays >= -1) && (diffDays <= 1)) {
|
|
812
|
+
parts = rtf.formatToParts(diffDays, "day");
|
|
813
|
+
}
|
|
814
|
+
else if ((diffDays >= -6) && (diffDays < -1)) {
|
|
815
|
+
prefix = this.dddd + ', ';
|
|
816
|
+
parts = rtf.formatToParts(diffDays, "day");
|
|
817
|
+
}
|
|
818
|
+
else if ((diffDays <= 6) && (diffDays > 1)) {
|
|
819
|
+
prefix = this.dddd;
|
|
820
|
+
parts = [];
|
|
808
821
|
}
|
|
809
822
|
else {
|
|
810
823
|
return this.fdate();
|
|
811
824
|
}
|
|
812
|
-
|
|
825
|
+
bbn.fn.each(parts, (part) => {
|
|
826
|
+
phrase += part.value;
|
|
827
|
+
});
|
|
828
|
+
return `${prefix}${phrase} ${this.ftime()}`;
|
|
813
829
|
}
|
|
814
830
|
matchFormat(value, format) {
|
|
815
831
|
try {
|
|
@@ -1188,7 +1204,6 @@ export class bbnDt {
|
|
|
1188
1204
|
else {
|
|
1189
1205
|
return 28;
|
|
1190
1206
|
}
|
|
1191
|
-
case 1:
|
|
1192
1207
|
case 4:
|
|
1193
1208
|
case 6:
|
|
1194
1209
|
case 9:
|