Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
π Restore 6 missing time zones and show modern city names (#3035)
Luke Velladf890b8fde03
diff --git a/apps/web/src/components/time-zone-picker/time-zone-select.test.tsx b/apps/web/src/components/time-zone-picker/time-zone-select.test.tsxindex 0c6496e2c..83dfd31e2 100644--- a/apps/web/src/components/time-zone-picker/time-zone-select.test.tsx+++ b/apps/web/src/components/time-zone-picker/time-zone-select.test.tsx@@ -1,8 +1,16 @@import userEvent from "@testing-library/user-event";import { describe, expect, it } from "vitest";+import { toRuntimeCanonicalIanaId } from "@/lib/utils/timezone-schema";import { render, screen, within } from "@/test/test-utils";import { TimeZoneSelect } from "./time-zone-select";+import {+ curatedTimezoneIds,+ getAllTimezoneIds,+ getCityFromTimezoneId,+ getCuratedTimezoneIds,+ matchesTimezoneQuery,+} from "./timezone-data";describe("TimeZoneSelect", () => {it("should render the combobox input", () => {@@ -106,3 +114,118 @@ describe("TimeZoneSelect", () => {expect(input).toHaveAttribute("data-list-empty", "");});});++describe("curated timezone list", () => {+ const curatedIds = getCuratedTimezoneIds(getAllTimezoneIds());++ const curatedCanonicalIds = new Set(curatedIds.map(toRuntimeCanonicalIanaId));++ it.each(+ Array.from(curatedTimezoneIds),+ )("keeps %s in the curated list", (curatedId) => {+ // A curated ID that matches nothing must fail here rather than vanish+ // from the default view. CLDR/ICU keeps pre-2008 tzdb IDs canonical, so+ // the runtime lists `Asia/Calcutta` where we curate `Asia/Kolkata`; the+ // intersection compares canonical forms so both spellings match.+ // Compare canonical IDs, not city labels β a label is not an identity, so+ // a label assertion would pass if a different zone shared the name.+ expect(curatedCanonicalIds).toContain(toRuntimeCanonicalIanaId(curatedId));+ });++ it("shows modern city names for zones the runtime spells with legacy IDs", () => {+ const cities = curatedIds.map(getCityFromTimezoneId);++ expect(cities).toContain("Kolkata");+ expect(cities).toContain("Kathmandu");+ expect(cities).toContain("Yangon");+ expect(cities).toContain("Ho Chi Minh");+ expect(cities).toContain("Buenos Aires");+ expect(cities).toContain("Kyiv");++ expect(cities).not.toContain("Calcutta");+ expect(cities).not.toContain("Katmandu");+ expect(cities).not.toContain("Rangoon");+ expect(cities).not.toContain("Saigon");+ expect(cities).not.toContain("Kiev");+ });++ it("does not duplicate a zone the runtime and curated set spell differently", () => {+ const kolkata = curatedIds.filter(+ (id) => getCityFromTimezoneId(id) === "Kolkata",+ );+ expect(kolkata).toHaveLength(1);+ });++ it("has one curated entry per zone", () => {+ expect(curatedCanonicalIds.size).toBe(curatedIds.length);+ });+});++describe("timezone search", () => {+ // Both directions: whichever spelling the runtime lists, either query finds+ // it. This runtime lists the legacy IDs, so the modern-ID cases guard against+ // engines that do the opposite.+ it.each([+ ["Asia/Calcutta", "Asia/Kolkata", "calcutta", "kolkata"],+ ["Asia/Katmandu", "Asia/Kathmandu", "katmandu", "kathmandu"],+ ["Asia/Rangoon", "Asia/Yangon", "rangoon", "yangon"],+ ["Asia/Saigon", "Asia/Ho_Chi_Minh", "saigon", "ho chi minh"],+ ["Europe/Kiev", "Europe/Kyiv", "kiev", "kyiv"],+ [+ "America/Buenos_Aires",+ "America/Argentina/Buenos_Aires",+ "buenos aires",+ "buenos aires",+ ],+ ])("matches %s and %s by either alias", (legacyId, modernId, legacyQuery, modernQuery) => {+ for (const id of [legacyId, modernId]) {+ expect(matchesTimezoneQuery(id, legacyQuery)).toBe(true);+ expect(matchesTimezoneQuery(id, modernQuery)).toBe(true);+ }+ });+});++describe("stored value round trip", () => {+ it.each([+ "Asia/Kolkata",+ "Asia/Kathmandu",+ "Asia/Yangon",+ "Asia/Ho_Chi_Minh",+ "Europe/Kyiv",+ "America/Argentina/Buenos_Aires",+ ])("marks %s as selected when stored in its modern spelling", async (stored) => {+ // `timezoneSchema` persists modern IDs while the runtime lists legacy+ // ones, so a stored value must still resolve to the item the list+ // renders β otherwise the saved zone reopens with nothing selected.+ const user = userEvent.setup();+ render(<TimeZoneSelect value={stored} />);++ await user.click(screen.getByRole("combobox"));++ const listbox = await screen.findByRole("listbox");+ const selected = within(listbox)+ .getAllByRole("option")+ .filter((option) => option.getAttribute("aria-selected") === "true");++ expect(selected).toHaveLength(1);+ expect(selected[0].textContent).toContain(getCityFromTimezoneId(stored));+ });++ it("reports the modern spelling when a legacy-listed zone is picked", async () => {+ const onValueChange = vi.fn();+ const user = userEvent.setup();+ render(<TimeZoneSelect onValueChange={onValueChange} />);++ await user.type(screen.getByRole("combobox"), "kolkata");++ const listbox = await screen.findByRole("listbox");+ const option = within(listbox)+ .getAllByRole("option")+ .find((opt) => opt.textContent?.includes("Kolkata"));++ if (!option) throw new Error("Kolkata option not found");+ await user.click(option);++ expect(onValueChange).toHaveBeenCalledWith("Asia/Kolkata");+ });+});diff --git a/apps/web/src/components/time-zone-picker/time-zone-select.tsx b/apps/web/src/components/time-zone-picker/time-zone-select.tsxindex 937c47635..6b5ab191e 100644--- a/apps/web/src/components/time-zone-picker/time-zone-select.tsx+++ b/apps/web/src/components/time-zone-picker/time-zone-select.tsx@@ -12,22 +12,38 @@ import { InputGroupAddon } from "@rallly/ui/input-group";import { GlobeIcon } from "lucide-react";import React from "react";import {- curatedTimezoneIds,getAllTimezoneIds,getCityFromTimezoneId,+ getCuratedTimezoneIds,+ matchesTimezoneQuery,} from "@/components/time-zone-picker/timezone-data";import { useTranslation } from "@/i18n/client";import { Time } from "@/lib/datetime/time";+import {+ normalizeLegacyIanaId,+ toRuntimeCanonicalIanaId,+} from "@/lib/utils/timezone-schema";const allIds = getAllTimezoneIds().sort((a, b) =>getCityFromTimezoneId(a).localeCompare(getCityFromTimezoneId(b)),);-const curatedIds = allIds.filter((id) => curatedTimezoneIds.has(id));+const curatedIds = getCuratedTimezoneIds(allIds);++const idByCanonicalForm = new Map(+ allIds.map((id) => [toRuntimeCanonicalIanaId(id), id]),+);-function filterTimezone(id: string, query: string): boolean {- if (!query) return true;- return getCityFromTimezoneId(id).toLowerCase().includes(query.toLowerCase());+/**+ * Map a stored ID onto the exact item the list renders.+ *+ * Values are persisted in the modern spelling (`timezoneSchema` normalizes on+ * write), while the runtime lists the legacy one. Passing the stored ID+ * straight through leaves the combobox unable to match any item, so the saved+ * zone renders unselected. Selecting by canonical form fixes that.+ */+function toItemId(value: string) {+ return idByCanonicalForm.get(toRuntimeCanonicalIanaId(value)) ?? value;}export function TimeZoneSelect({@@ -57,10 +73,12 @@ export function TimeZoneSelect({return (<Comboboxitems={isSearching ? allIds : curatedIds}- value={value ?? null}+ value={value ? toItemId(value) : null}onValueChange={(id) => {if (id) {- onValueChange?.(id);+ // Report the modern spelling regardless of how the runtime spells it,+ // so callers persist a stable, tzdb-canonical ID.+ onValueChange?.(normalizeLegacyIanaId(id));}}}onInputValueChange={(inputValue, { reason }) => {@@ -71,7 +89,7 @@ export function TimeZoneSelect({}}}itemToStringLabel={getCityFromTimezoneId}- filter={filterTimezone}+ filter={matchesTimezoneQuery}autoHighlight={true}><div ref={anchorRef} className={cn("min-w-64", className)}>diff --git a/apps/web/src/components/time-zone-picker/timezone-data.ts b/apps/web/src/components/time-zone-picker/timezone-data.tsindex 80a7acd80..a50615ac6 100644--- a/apps/web/src/components/time-zone-picker/timezone-data.ts+++ b/apps/web/src/components/time-zone-picker/timezone-data.ts@@ -1,4 +1,8 @@-import { normalizeLegacyIanaId } from "@/lib/utils/timezone-schema";+import {+ getIanaIdAliases,+ normalizeLegacyIanaId,+ toRuntimeCanonicalIanaId,+} from "@/lib/utils/timezone-schema";export function getAllTimezoneIds(): string[] {return Intl.supportedValuesOf("timeZone");@@ -10,6 +14,43 @@ export function getCityFromTimezoneId(id: string): string {return resolved.substring(lastSlash + 1).replaceAll("_", " ");}+/**+ * The curated IDs as this runtime spells them.+ *+ * CLDR/ICU keeps pre-2008 tzdb IDs canonical, so `Intl.supportedValuesOf`+ * yields `Asia/Calcutta` where the curated set lists `Asia/Kolkata`. A raw+ * string intersection silently drops those entries, so compare canonical forms+ * on both sides instead. `time-zone-select.test.tsx` asserts no curated entry+ * goes missing.+ */+export function getCuratedTimezoneIds(allIds: string[]) {+ const curatedCanonical = new Set(+ Array.from(curatedTimezoneIds, toRuntimeCanonicalIanaId),+ );+ return allIds.filter((id) =>+ curatedCanonical.has(toRuntimeCanonicalIanaId(id)),+ );+}++/**+ * Match a query against every spelling of the zone, so someone typing+ * "Calcutta" still finds the zone shown as "Kolkata" β and vice versa on an+ * engine that lists the modern ID.+ */+export function matchesTimezoneQuery(id: string, query: string) {+ const normalizedQuery = query.trim().toLowerCase();+ if (!normalizedQuery) return true;++ for (const candidate of getIanaIdAliases(id)) {+ const lastSlash = candidate.lastIndexOf("/");+ const city = candidate.substring(lastSlash + 1).replaceAll("_", " ");+ if (city.toLowerCase().includes(normalizedQuery)) {+ return true;+ }+ }+ return false;+}+// Curated set of major cities/timezones covering most common UTC offsets.// Some rare offsets (e.g. UTC-9:30, UTC+8:45, UTC+12:45) are omitted intentionally.export const curatedTimezoneIds = new Set([diff --git a/apps/web/src/lib/utils/timezone-schema.ts b/apps/web/src/lib/utils/timezone-schema.tsindex 8c8b7058e..0c58f299f 100644--- a/apps/web/src/lib/utils/timezone-schema.ts+++ b/apps/web/src/lib/utils/timezone-schema.ts@@ -1,7 +1,14 @@import * as z from "zod";-// Override runtime canonicalization when ICU data lags behind IANA updates.+// CLDR/ICU keeps pre-2008 tzdb IDs canonical for stability, so the runtime+// reports (and `Intl.supportedValuesOf` lists) the outdated spellings. Map them+// back to the modern tzdb-canonical names for display.const ianaOverrides: Record<string, string> = {+ "America/Buenos_Aires": "America/Argentina/Buenos_Aires",+ "Asia/Calcutta": "Asia/Kolkata",+ "Asia/Katmandu": "Asia/Kathmandu",+ "Asia/Rangoon": "Asia/Yangon",+ "Asia/Saigon": "Asia/Ho_Chi_Minh","Europe/Kiev": "Europe/Kyiv",};@@ -9,6 +16,43 @@ export function normalizeLegacyIanaId(id: string): string {return ianaOverrides[id] ?? id;}+const legacyIdsByModernId = Object.entries(ianaOverrides).reduce<+ Record<string, string[]>+>((acc, [legacy, modern]) => {+ acc[modern] = [...(acc[modern] ?? []), legacy];+ return acc;+}, {});++/**+ * Every spelling of a zone we know about β modern and legacy β for the given+ * ID, whichever spelling it arrives in. Used for search, so a query matches an+ * alias no matter which form the runtime happens to list.+ */+export function getIanaIdAliases(id: string) {+ const modern = normalizeLegacyIanaId(id);+ return Array.from(+ new Set([id, modern, ...(legacyIdsByModernId[modern] ?? [])]),+ );+}++/**+ * Fold an IANA ID to whatever spelling this runtime treats as canonical.+ *+ * The inverse of `normalizeLegacyIanaId`: that maps legacy IDs to modern names+ * for display, this maps either spelling to the runtime's own. Comparing IDs by+ * this form matches a curated `Asia/Kolkata` against a runtime `Asia/Calcutta`+ * without depending on the override map covering that pair, so engines whose+ * affected set differs are handled too. Unknown IDs are returned unchanged.+ */+export function toRuntimeCanonicalIanaId(id: string): string {+ try {+ return Intl.DateTimeFormat(undefined, { timeZone: id }).resolvedOptions()+ .timeZone;+ } catch {+ return id;+ }+}+const fixedOffsetPrefixes = ["etc/", "gmt", "utc"];function isGeographic(timeZone: string) {