diff --git a/src/components/input-time-picker/input-time-picker.e2e.ts b/src/components/input-time-picker/input-time-picker.e2e.ts index e0a94d86051..c510293ecc4 100644 --- a/src/components/input-time-picker/input-time-picker.e2e.ts +++ b/src/components/input-time-picker/input-time-picker.e2e.ts @@ -33,6 +33,18 @@ describe("calcite-input-time-picker", () => { renders(``, { display: "inline-block" }); }); + describe("renders with base lang when region code is unsupported", () => { + renders(``, { display: "inline-block" }); + }); + + describe("renders with pt-PT locale", () => { + renders(``, { display: "inline-block" }); + }); + + describe("renders with no locale", () => { + renders(``, { display: "inline-block" }); + }); + describe("honors hidden attribute", () => { hidden("calcite-input-time-picker"); }); diff --git a/src/components/input-time-picker/input-time-picker.tsx b/src/components/input-time-picker/input-time-picker.tsx index 2123eae53f8..ed0f062879d 100644 --- a/src/components/input-time-picker/input-time-picker.tsx +++ b/src/components/input-time-picker/input-time-picker.tsx @@ -62,6 +62,7 @@ import localeData from "dayjs/esm/plugin/localeData"; import localizedFormat from "dayjs/esm/plugin/localizedFormat"; import preParsePostFormat from "dayjs/esm/plugin/preParsePostFormat"; import updateLocale from "dayjs/esm/plugin/updateLocale"; +import { getSupportedLocale } from "../../utils/locale"; // some bundlers (e.g., Webpack) need dynamic import paths to be static const supportedDayJsLocaleToLocaleConfigImport = new Map([ @@ -555,18 +556,22 @@ export class InputTimePicker }; private async loadDateTimeLocaleData(): Promise { - const normalizedLocale = this.getNormalizedLocale(); + let supportedLocale = getSupportedLocale(this.effectiveLocale).toLowerCase(); - if (normalizedLocale === "en" || normalizedLocale === "en-us") { - return; + if (supportedLocale === "no") { + supportedLocale = "nb"; + } + + if (supportedLocale === "pt-pt") { + supportedLocale = "pt"; } const { default: localeConfig } = await supportedDayJsLocaleToLocaleConfigImport.get( - normalizedLocale + supportedLocale )(); dayjs.locale(localeConfig, null, true); - dayjs.updateLocale(normalizedLocale, this.getExtendedLocaleConfig(normalizedLocale)); + dayjs.updateLocale(supportedLocale, this.getExtendedLocaleConfig(supportedLocale)); } private getExtendedLocaleConfig( @@ -644,22 +649,6 @@ export class InputTimePicker } } - private getNormalizedLocale(): string { - const { effectiveLocale } = this; - let normalizedLocale = effectiveLocale ? effectiveLocale.toLowerCase() : "en"; - - if (normalizedLocale === "en-us") { - normalizedLocale = "en"; - } - if (normalizedLocale === "pt-pt") { - normalizedLocale = "pt"; - } - if (normalizedLocale === "no") { - normalizedLocale = "nb"; - } - return normalizedLocale; - } - onLabelClick(): void { this.setFocus(); } @@ -765,8 +754,6 @@ export class InputTimePicker connectedCallback() { connectLocalized(this); - this.effectiveLocale = this.getNormalizedLocale(); - if (isValidTime(this.value)) { this.setValueDirectly(this.value); } else {