@fluid-topics/ft-wc-utils 2.0.11 → 2.0.13

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.
@@ -5,7 +5,7 @@ declare global {
5
5
  }
6
6
  }
7
7
  export declare class DateFormatter {
8
- static format(date: string | Date, locale: string, longDateFormat: boolean, dateTimeFormat: boolean): string;
8
+ static format(date: string | Date, locale: string, longDateFormat: boolean, dateTimeFormat: boolean, onlyTimeFormat?: boolean): string;
9
9
  private static getMomentDateFormat;
10
10
  private static getIntlDateTime;
11
11
  static getTimezoneAsString(): string;
@@ -1,11 +1,14 @@
1
1
  export class DateFormatter {
2
- static format(date, locale, longDateFormat, dateTimeFormat) {
2
+ static format(date, locale, longDateFormat, dateTimeFormat, onlyTimeFormat) {
3
3
  if (!window.moment) {
4
- return this.getIntlDateTime(date, locale, longDateFormat, dateTimeFormat);
4
+ return this.getIntlDateTime(date, locale, longDateFormat, dateTimeFormat, !!onlyTimeFormat);
5
5
  }
6
- return window.moment(date).locale(locale).format(this.getMomentDateFormat(longDateFormat, dateTimeFormat));
6
+ return window.moment(date).locale(locale).format(this.getMomentDateFormat(longDateFormat, dateTimeFormat, !!onlyTimeFormat));
7
7
  }
8
- static getMomentDateFormat(longDateFormat, dateTimeFormat) {
8
+ static getMomentDateFormat(longDateFormat, dateTimeFormat, onlyTimeFormat) {
9
+ if (onlyTimeFormat) {
10
+ return "LT";
11
+ }
9
12
  if (longDateFormat) {
10
13
  if (dateTimeFormat) {
11
14
  return "lll";
@@ -19,13 +22,16 @@ export class DateFormatter {
19
22
  return "L";
20
23
  }
21
24
  }
22
- static getIntlDateTime(date, locale, longDateFormat, dateTimeFormat) {
25
+ static getIntlDateTime(date, locale, longDateFormat, dateTimeFormat, onlyTimeFormat) {
23
26
  const parsedDate = typeof date === "string" ? new Date(date) : date;
24
27
  const datePart = (new Intl.DateTimeFormat(locale, { dateStyle: longDateFormat ? "medium" : "short" })).format(parsedDate);
28
+ const timePart = (new Intl.DateTimeFormat(locale, { timeStyle: "short" })).format(parsedDate);
29
+ if (onlyTimeFormat) {
30
+ return timePart;
31
+ }
25
32
  if (!dateTimeFormat) {
26
33
  return datePart;
27
34
  }
28
- const timePart = (new Intl.DateTimeFormat(locale, { timeStyle: "short" })).format(parsedDate);
29
35
  return `${datePart} ${timePart}`;
30
36
  }
31
37
  static getTimezoneAsString() {