Skip to content

fix(input-time-zone): fix error caused by time zone group filtering #7971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ describe("calcite-input-time-zone", () => {

expect(await timeZoneItem.getProperty("textLabel")).toMatch(testTimeZoneNamesAndOffsets[0].label);
});

it("omits filtered or non-localized time zones (incoming to browser)", async () => {
const page = await newE2EPage();
await page.emulateTimezone(testTimeZoneNamesAndOffsets[0].name);
await page.setContent(
await addTimeZoneNamePolyfill(html` <calcite-input-time-zone value="60"></calcite-input-time-zone>`)
);

const input = await page.find("calcite-input-time-zone");

expect(await input.getProperty("value")).toBe(`${testTimeZoneNamesAndOffsets[2].offset}`);

const timeZoneItem = await page.find("calcite-input-time-zone >>> calcite-combobox-item[selected]");

expect(await timeZoneItem.getProperty("textLabel")).toMatch(testTimeZoneNamesAndOffsets[2].label);
});
});

describe("name", () => {
Expand Down Expand Up @@ -269,7 +285,7 @@ function addTimeZoneNamePolyfill(testHtml: string): string {
? "-7"
: timeZone === "America/Denver"
? "-6"
: timeZone === "Europe/London"
: timeZone === "Europe/London" || timeZone === "Europe/Belfast" || timeZone === "Etc/GMT-1"
? "+1"
: "+0");

Expand Down Expand Up @@ -298,7 +314,15 @@ function addTimeZoneNamePolyfill(testHtml: string): string {

Intl.supportedValuesOf = function (key) {
if (key === "timeZone") {
return ["America/Los_Angeles", "America/Denver", "Europe/London"];
return [
"America/Los_Angeles",
"America/Denver",
"Europe/London",

// not available in Chromium v92 at time of testing
"Etc/GMT-1",
"Europe/Belfast",
];
}
};
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,18 @@ export async function createTimeZoneItems(
const indexOffsets: number[] = [];
let removedSoFar = 0;

group.tzs = group.tzs.filter((tz) => {
group.tzs.forEach((tz, index) => {
if (timeZoneNameBlockList.includes(tz)) {
removedSoFar++;
return false;
}

indexOffsets.push(removedSoFar);
return true;
indexOffsets[index] = removedSoFar;
});

group.tzs = group.tzs.filter((tz) => !timeZoneNameBlockList.includes(tz));

group.labelTzIndices = group.labelTzIndices
.map((index) => index - (indexOffsets[index] || 0))
.filter((index) => index < group.tzs.length);
.map((index) => index - indexOffsets[index])
.filter((index) => index >= 0 && index < group.tzs.length);
});

return timeZoneGroups
Expand Down