fix: Timezone Select invalid labels as DST unsupported in spacetime (#14056)
* Fix: Timezone Select invalid labels as DST unsupported in spacetime * Missed a _ -> (empty string) replace causing invalid TZs * fix: getTimezone tests didnt support DST
This commit is contained in:
1 parent
12e171823b
commit
e3a5ce5f6e
3 files changed
+45
-27
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type { ITimezoneOption } from "react-timezone-select";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { ICity } from "@calcom/ui/components/form/timezone-select";
|
||||
|
||||
import isProblematicTimezone from "./isProblematicTimezone";
|
||||
@@ -32,9 +33,15 @@ export const addCitiesToDropdown = (cities: ICity[]) => {
|
||||
return cityTimezones || {};
|
||||
};
|
||||
|
||||
const formatOffset = (offset: string) =>
|
||||
offset.replace(/^([-+])(0)(\d):00$/, (_, sign, _zero, hour) => `${sign}${hour}:00`);
|
||||
|
||||
export const handleOptionLabel = (option: ITimezoneOption, cities: ICity[]) => {
|
||||
const timezoneValue = option.label.split(")")[0].replace("(", " ").replace("T", "T ");
|
||||
const offsetUnit = option.label.split("-")[0].substring(1);
|
||||
const cityName = option.label.split(") ")[1];
|
||||
const refactoredOption = option.value.replace(/_/g, " ");
|
||||
return cities.length > 0 ? `${cityName}${timezoneValue}` : `${refactoredOption}${timezoneValue}`;
|
||||
|
||||
const timezoneValue = ` ${offsetUnit} ${formatOffset(dayjs.tz(undefined, option.value).format("Z"))}`;
|
||||
return cities.length > 0
|
||||
? `${cityName}${timezoneValue}`
|
||||
: `${option.value.replace(/_/g, " ")}${timezoneValue}`;
|
||||
};
|
||||
Reference in new issue
Block a user