|
1 | 1 | import type DateFormatT from "sap/ui/core/format/DateFormat"; |
2 | 2 | // @ts-ignore |
3 | 3 | import DateFormatNative from "./sap/ui/core/format/DateFormat.js"; |
| 4 | +import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js"; |
| 5 | +import LocaleWrapped from "./Locale.js"; |
| 6 | +import type CalendarWeekNumbering from "sap/base/i18n/date/CalendarWeekNumbering"; |
| 7 | +import type CalendarType from "sap/base/i18n/date/CalendarType"; |
| 8 | + |
| 9 | +type DateFormatOptions = { |
| 10 | + calendarWeekNumbering?: CalendarWeekNumbering | keyof typeof CalendarWeekNumbering; |
| 11 | + firstDayOfWeek?: int; |
| 12 | + minimalDaysInFirstWeek?: int; |
| 13 | + format?: string; |
| 14 | + pattern?: string; |
| 15 | + style?: string; |
| 16 | + strictParsing?: boolean; |
| 17 | + relative?: boolean; |
| 18 | + relativeRange?: int[]; |
| 19 | + relativeScale?: string; |
| 20 | + relativeStyle?: string; |
| 21 | + interval?: boolean; |
| 22 | + intervalDelimiter?: string; |
| 23 | + singleIntervalValue?: boolean; |
| 24 | + UTC?: boolean; |
| 25 | + calendarType?: CalendarType | keyof typeof CalendarType; |
| 26 | +}; |
4 | 27 |
|
5 | 28 | const DateFormatWrapped = DateFormatNative as typeof DateFormatT; |
6 | | -class DateFormat extends DateFormatWrapped {} |
| 29 | + |
| 30 | +class DateFormat extends DateFormatWrapped { |
| 31 | + static getDateInstance(oFormatOptions?: DateFormatOptions, oLocale?: LocaleWrapped): DateFormat; |
| 32 | + static getDateInstance(oLocale?: LocaleWrapped): DateFormat; |
| 33 | + static getDateInstance(oFormatOptionsOrLocale?: DateFormatOptions | LocaleWrapped, oLocale?: LocaleWrapped): DateFormat { |
| 34 | + if (oFormatOptionsOrLocale instanceof LocaleWrapped) { |
| 35 | + return DateFormatWrapped.getDateInstance(undefined, oFormatOptionsOrLocale); |
| 36 | + } |
| 37 | + const nativeLocale = oLocale ?? new LocaleWrapped(getLocale().toString()); |
| 38 | + return DateFormatWrapped.getDateInstance(oFormatOptionsOrLocale, nativeLocale); |
| 39 | + } |
| 40 | +} |
7 | 41 |
|
8 | 42 | export default DateFormat; |
0 commit comments