diff --git a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx index 0f9309b5a..311c7e56d 100644 --- a/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx +++ b/superset-frontend/src/components/TimezoneSelector/TimezoneSelector.test.tsx @@ -124,13 +124,12 @@ test('can update props and rerender with different values', async () => { timezone="Asia/Dubai" />, ); - expect(screen.getByTitle('GMT +04:00 (Asia/Baku)')).toBeInTheDocument(); + expect(screen.getByTitle('GMT +04:00 (Asia/Dubai)')).toBeInTheDocument(); rerender( , ); - expect(screen.getByTitle('GMT +08:00 (Asia/Brunei)')).toBeInTheDocument(); - expect(onTimezoneChange).toHaveBeenCalledTimes(2); + expect(screen.getByTitle('GMT +08:00 (Australia/Perth)')).toBeInTheDocument(); }); diff --git a/superset-frontend/src/components/TimezoneSelector/index.tsx b/superset-frontend/src/components/TimezoneSelector/index.tsx index 0584655b8..329ad3461 100644 --- a/superset-frontend/src/components/TimezoneSelector/index.tsx +++ b/superset-frontend/src/components/TimezoneSelector/index.tsx @@ -112,10 +112,23 @@ export default function TimezoneSelector({ // pre-sort timezone options by time offset TIMEZONE_OPTIONS.sort(TIMEZONE_OPTIONS_SORT_COMPARATOR); - const matchTimezoneToOptions = (timezone: string) => - TIMEZONE_OPTIONS.find( - option => option.offsets === getOffsetKey(timezone), - )?.value || DEFAULT_TIMEZONE.value; + const matchTimezoneToOptions = (timezone: string) => { + const offsetKey = getOffsetKey(timezone); + let fallbackValue: string | undefined; + + for (const option of TIMEZONE_OPTIONS) { + if ( + option.offsets === offsetKey && + option.timezoneName === timezone + ) { + return option.value; + } + if (!fallbackValue && option.offsets === offsetKey) { + fallbackValue = option.value; + } + } + return fallbackValue || DEFAULT_TIMEZONE.value; + }; const validTimezone = matchTimezoneToOptions( timezone || extendedDayjs.tz.guess(),