diff --git a/client/src/Features/UI/uiSlice.ts b/client/src/Features/UI/uiSlice.ts index 84e8248db..be54eead8 100644 --- a/client/src/Features/UI/uiSlice.ts +++ b/client/src/Features/UI/uiSlice.ts @@ -89,7 +89,9 @@ const uiSlice = createSlice({ }, setTimezone: (state, action: PayloadAction<{ timezone: string }>) => { - state.timezone = action.payload.timezone; + if (action.payload.timezone) { + state.timezone = action.payload.timezone; + } }, setLanguage: (state, action: PayloadAction) => { state.language = action.payload; diff --git a/client/src/Pages/Settings/index.tsx b/client/src/Pages/Settings/index.tsx index fc3fceceb..3c6e8a3a1 100644 --- a/client/src/Pages/Settings/index.tsx +++ b/client/src/Pages/Settings/index.tsx @@ -128,8 +128,8 @@ export const SettingsPage = () => { timezoneOptions.find((tz) => tz.id === selectedTimezoneId) ?? null; const handleTimezoneChange = (newValue: Timezone | null) => { - const newId = newValue?.id ?? ""; - dispatch(setTimezone({ timezone: newId })); + if (!newValue?.id) return; + dispatch(setTimezone({ timezone: newValue.id })); }; const handleModeChange = (e: SelectChangeEvent) => { diff --git a/client/src/Utils/TimeUtils.ts b/client/src/Utils/TimeUtils.ts index abd56ce44..cffdd5440 100644 --- a/client/src/Utils/TimeUtils.ts +++ b/client/src/Utils/TimeUtils.ts @@ -19,8 +19,11 @@ export const formatDateWithTz = (timestamp: string, format: string, timezone: st if (!timestamp) { return "Unknown time"; } - const formattedDate = dayjs(timestamp).tz(timezone).format(format); - return formattedDate; + try { + return dayjs(timestamp).tz(timezone).format(format); + } catch { + return dayjs(timestamp).utc().format(format); + } }; export const tickDateFormatLookup = (range: string) => {