@bbn/bbn 2.0.153 → 2.0.155

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.
@@ -97,7 +97,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
97
97
  format(format?: string): string;
98
98
  calendar(short?: boolean): string;
99
99
  matchFormat(value: any, format: string): boolean;
100
- getWeekday(n: 0 | 1 | 2 | 3 | 4 | 5 | 6, mode?: string, locale?: string): string | object;
100
+ getWeekday(n: number, mode?: string, locale?: string): string | object;
101
101
  getWeekdayIndex: (name: string, locale?: string) => number;
102
102
  /**
103
103
  * Returns a NEW date that is the next (or previous if past=true)
@@ -112,7 +112,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
112
112
  diff(date: any, unit?: string, abs?: boolean): number;
113
113
  guessUnit(valueInMs: number): string | null;
114
114
  fromNow(unit?: string): string;
115
- fromDate(date: bbnDt<any>, unit?: string): string;
115
+ from(date: bbnDt<any>, unit?: string): string;
116
116
  startOf(unit?: string): bbnDt<any>;
117
117
  endOf(unit?: string): bbnDt<any>;
118
118
  clone(): bbnDt<any>;
@@ -560,8 +560,8 @@ export class bbnDt {
560
560
  const diffDays = Math.floor((d.getTime() - jan1.getTime()) / MS_PER_DAY); // 0 for Jan 1
561
561
  const jan1Dow = jan1.getUTCDay(); // 0–6, Sunday=0
562
562
  // How many days long is week 1?
563
- // Week 1 starts on Jan 1 and ends the day before the first `weekStart` after Jan 1.
564
- let offset = (bbn.dt.locales.weekStart - jan1Dow + 7) % 7;
563
+ // Week 1 starts on Jan 1 and ends the day before the first `firstDayOfWeek` after Jan 1.
564
+ let offset = (bbn.dt.locales.firstDayOfWeek - jan1Dow + 7) % 7;
565
565
  const firstWeekLength = offset === 0 ? 7 : offset;
566
566
  // Still in the first (possibly partial) week
567
567
  if (diffDays < firstWeekLength) {
@@ -630,13 +630,13 @@ export class bbnDt {
630
630
  }
631
631
  get dddd() {
632
632
  if ('dayOfWeek' in this.value) {
633
- return this.getWeekday(0, 'long');
633
+ return this.getWeekday(this.value.dayOfWeek, 'long');
634
634
  }
635
635
  return undefined;
636
636
  }
637
637
  get ddd() {
638
- if ('day' in this.value) {
639
- return this.getWeekday(0, 'short');
638
+ if ('dayOfWeek' in this.value) {
639
+ return this.getWeekday(this.value.dayOfWeek, 'short');
640
640
  }
641
641
  return undefined;
642
642
  }
@@ -797,19 +797,32 @@ export class bbnDt {
797
797
  const startThis = this.startOf("day");
798
798
  const startNow = now.startOf("day");
799
799
  const diffDays = startThis.diff(startNow, "day");
800
- const rtf = new Intl.RelativeTimeFormat(bbn.env.lang, { numeric: "auto" });
801
- let phrase;
802
- if (Math.abs(diffDays) <= 6) {
803
- phrase = rtf.format(diffDays, "day");
800
+ const options = { numeric: "auto" };
801
+ if (short) {
802
+ options.style = "short";
803
+ }
804
+ const rtf = new Intl.RelativeTimeFormat(bbn.env.lang, options);
805
+ let phrase = '';
806
+ let parts = [];
807
+ let prefix = '';
808
+ if ((diffDays >= -1) && (diffDays <= 1)) {
809
+ parts = rtf.formatToParts(diffDays, "day");
804
810
  }
805
- else if (Math.abs(diffDays) <= 30) {
806
- const diffWeeks = Math.floor(diffDays / 7);
807
- phrase = rtf.format(diffWeeks, "week");
811
+ else if ((diffDays >= -6) && (diffDays < -1)) {
812
+ prefix = this.dddd + ', ';
813
+ parts = rtf.formatToParts(diffDays, "day");
814
+ }
815
+ else if ((diffDays <= 6) && (diffDays > 1)) {
816
+ prefix = this.dddd;
817
+ parts = [];
808
818
  }
809
819
  else {
810
820
  return this.fdate();
811
821
  }
812
- return `${phrase} ${this.ftime()}`;
822
+ bbn.fn.each(parts, (part) => {
823
+ phrase += part.value;
824
+ });
825
+ return `${prefix}${phrase} ${this.ftime()}`;
813
826
  }
814
827
  matchFormat(value, format) {
815
828
  try {
@@ -966,7 +979,7 @@ export class bbnDt {
966
979
  const [, rtfUnit] = match; // [shortUnit, rtfUnit, ms]
967
980
  return rtf.format(diff, rtfUnit);
968
981
  }
969
- fromDate(date, unit = '') {
982
+ from(date, unit = '') {
970
983
  const rawDiffMs = this.diff(date);
971
984
  const chosenUnit = unitsCorrespondence[unit] || this.guessUnit(rawDiffMs);
972
985
  if (!chosenUnit) {
@@ -1188,7 +1201,6 @@ export class bbnDt {
1188
1201
  else {
1189
1202
  return 28;
1190
1203
  }
1191
- case 1:
1192
1204
  case 4:
1193
1205
  case 6:
1194
1206
  case 9:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.153",
3
+ "version": "2.0.155",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",