Scheduling infrastructure for absolutely everyone.
fix: Invalid time zone specified: Etc/Unknown (#18121)
Anik Dhabal Babu645985c783fe
diff --git a/apps/web/lib/clock.ts b/apps/web/lib/clock.tsindex 3551c53f6ae..7c44f96dc91 100644--- a/apps/web/lib/clock.ts+++ b/apps/web/lib/clock.ts@@ -1,5 +1,5 @@// handles logic related to user clock display using 24h display / timeZone options.-import dayjs from "@calcom/dayjs";+import { CURRENT_TIMEZONE } from "@calcom/lib/constants";import {getIs24hClockFromLocalStorage,isBrowserLocale24h,@@ -26,8 +26,7 @@ const initClock = () => {// This only sets browser locale if there's no preference on localStorage.if (getIs24hClockFromLocalStorage() === null) set24hClock(isBrowserLocale24h());timeOptions.is24hClock = !!getIs24hClockFromLocalStorage();- timeOptions.inviteeTimeZone =- localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess() || "Europe/London";+ timeOptions.inviteeTimeZone = localStorage.getItem("timeOption.preferredTimeZone") || CURRENT_TIMEZONE;};const is24h = (is24hClock?: boolean) => {diff --git a/apps/web/modules/bookings/views/bookings-single-view.test.tsx b/apps/web/modules/bookings/views/bookings-single-view.test.tsxindex 9a2705626f6..24a3d3ff51b 100644--- a/apps/web/modules/bookings/views/bookings-single-view.test.tsx+++ b/apps/web/modules/bookings/views/bookings-single-view.test.tsx@@ -103,6 +103,13 @@ describe("Success Component", () => {vi.mocked(useRouterQuery).mockReturnValue({uid: "uid",});+ vi.mock("@calcom/lib/constants", async (importOriginal) => {+ const actual = await importOriginal<any>();+ return {+ ...actual,+ CURRENT_TIMEZONE: "Europe/London",+ };+ });vi.mocked(useSession).mockReturnValue({update: vi.fn(),status: "authenticated",diff --git a/apps/web/modules/bookings/views/bookings-single-view.tsx b/apps/web/modules/bookings/views/bookings-single-view.tsxindex 623171b7127..0f7662717b5 100644--- a/apps/web/modules/bookings/views/bookings-single-view.tsx+++ b/apps/web/modules/bookings/views/bookings-single-view.tsx@@ -31,7 +31,7 @@ import {SystemField,TITLE_FIELD,} from "@calcom/features/bookings/lib/SystemField";-import { APP_NAME } from "@calcom/lib/constants";+import { APP_NAME, CURRENT_TIMEZONE } from "@calcom/lib/constants";import {formatToLocalizedDate,formatToLocalizedTime,@@ -258,9 +258,7 @@ export default function Success(props: PageProps) {}, [telemetry]); */useEffect(() => {- setDate(- date.tz(localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess() || "Europe/London")- );+ setDate(date.tz(localStorage.getItem("timeOption.preferredTimeZone") || CURRENT_TIMEZONE));setIs24h(props?.userTimeFormat ? props.userTimeFormat === 24 : !!getIs24hClockFromLocalStorage());// eslint-disable-next-line react-hooks/exhaustive-deps}, [eventType, needsConfirmation]);diff --git a/packages/features/bookings/lib/timePreferences.ts b/packages/features/bookings/lib/timePreferences.tsindex 7619685622c..4eeb742fee1 100644--- a/packages/features/bookings/lib/timePreferences.ts+++ b/packages/features/bookings/lib/timePreferences.ts@@ -1,6 +1,6 @@import { create } from "zustand";-import dayjs from "@calcom/dayjs";+import { CURRENT_TIMEZONE } from "@calcom/lib/constants";import { TimeFormat, detectBrowserTimeFormat, setIs24hClockInLocalStorage } from "@calcom/lib/timeFormat";import { localStorage } from "@calcom/lib/webstorage";@@ -24,7 +24,7 @@ export const timePreferencesStore = create<TimePreferencesStore>((set) => ({setIs24hClockInLocalStorage(format === TimeFormat.TWENTY_FOUR_HOUR);set({ timeFormat: format });},- timezone: localStorage.getItem(timezoneLocalStorageKey) || dayjs.tz.guess() || "Europe/London",+ timezone: localStorage.getItem(timezoneLocalStorageKey) || CURRENT_TIMEZONE,setTimezone: (timezone: string) => {localStorage.setItem(timezoneLocalStorageKey, timezone);set({ timezone });diff --git a/packages/features/ee/payments/components/PaymentPage.tsx b/packages/features/ee/payments/components/PaymentPage.tsxindex 36a9f9320f7..626acdafcd3 100644--- a/packages/features/ee/payments/components/PaymentPage.tsx+++ b/packages/features/ee/payments/components/PaymentPage.tsx@@ -11,7 +11,7 @@ import dayjs from "@calcom/dayjs";import { sdkActionManager, useIsEmbed } from "@calcom/embed-core/embed-iframe";import { PayIcon } from "@calcom/features/bookings/components/event-meta/PayIcon";import { Price } from "@calcom/features/bookings/components/event-meta/Price";-import { APP_NAME, WEBSITE_URL } from "@calcom/lib/constants";+import { APP_NAME, WEBSITE_URL, CURRENT_TIMEZONE } from "@calcom/lib/constants";import getPaymentAppData from "@calcom/lib/getPaymentAppData";import { useLocale } from "@calcom/lib/hooks/useLocale";import useTheme from "@calcom/lib/hooks/useTheme";@@ -51,8 +51,7 @@ const PaymentPage: FC<PaymentPageProps> = (props) => {const paymentAppData = getPaymentAppData(props.eventType);useEffect(() => {let embedIframeWidth = 0;- const _timezone =- localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess() || "Europe/London";+ const _timezone = localStorage.getItem("timeOption.preferredTimeZone") || CURRENT_TIMEZONE;setTimezone(_timezone);setDate(date.tz(_timezone));setIs24h(!!getIs24hClockFromLocalStorage());diff --git a/packages/features/ee/teams/components/TeamAvailabilityModal.tsx b/packages/features/ee/teams/components/TeamAvailabilityModal.tsxindex a39d3003589..48003c5e5bf 100644--- a/packages/features/ee/teams/components/TeamAvailabilityModal.tsx+++ b/packages/features/ee/teams/components/TeamAvailabilityModal.tsx@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";import dayjs from "@calcom/dayjs";import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired";-import { WEBAPP_URL } from "@calcom/lib/constants";+import { WEBAPP_URL, CURRENT_TIMEZONE } from "@calcom/lib/constants";import { useLocale } from "@calcom/lib/hooks/useLocale";import type { RouterOutputs } from "@calcom/trpc/react";import { trpc } from "@calcom/trpc/react";@@ -20,7 +20,7 @@ export default function TeamAvailabilityModal(props: Props) {const utils = trpc.useUtils();const [selectedDate, setSelectedDate] = useState(dayjs());const [selectedTimeZone, setSelectedTimeZone] = useState<ITimezone>(- localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess() || "Europe/London"+ localStorage.getItem("timeOption.preferredTimeZone") || CURRENT_TIMEZONE);const { t } = useLocale();diff --git a/packages/features/settings/TimezoneChangeDialog.tsx b/packages/features/settings/TimezoneChangeDialog.tsxindex 2b2d8493404..5df01f612de 100644--- a/packages/features/settings/TimezoneChangeDialog.tsx+++ b/packages/features/settings/TimezoneChangeDialog.tsx@@ -5,6 +5,7 @@ import { useSession } from "next-auth/react";import { useEffect, useState } from "react";import dayjs from "@calcom/dayjs";+import { CURRENT_TIMEZONE } from "@calcom/lib/constants";import { useLocale } from "@calcom/lib/hooks/useLocale";import { trpc } from "@calcom/trpc/react";import { showToast, Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader } from "@calcom/ui";@@ -22,8 +23,7 @@ const TimezoneChangeDialogContent = () => {const utils = trpc.useUtils();- const browserTimezone = dayjs.tz.guess() || "Europe/London";- const formattedCurrentTz = browserTimezone.replace("_", " ");+ const formattedCurrentTz = CURRENT_TIMEZONE.replace("_", " ");const onMutationSuccess = async () => {showToast(t("updated_timezone_to", { formattedCurrentTz }), "success");@@ -42,7 +42,7 @@ const TimezoneChangeDialogContent = () => {const updateTimezone = () => {mutation.mutate({- timeZone: browserTimezone,+ timeZone: CURRENT_TIMEZONE,});};@@ -77,8 +77,10 @@ export function useOpenTimezoneDialog() {if (!user?.timeZone || status !== "authenticated" || userSession?.user?.impersonatedBy) {return;}- const browserTimezone = dayjs.tz.guess() || "Europe/London";- if (dayjs.tz(undefined, browserTimezone).utcOffset() !== dayjs.tz(undefined, user.timeZone).utcOffset()) {++ if (+ dayjs.tz(undefined, CURRENT_TIMEZONE).utcOffset() !== dayjs.tz(undefined, user.timeZone).utcOffset()+ ) {setShowDialog(true);}}, [user?.timeZone, status, userSession?.user?.impersonatedBy]);diff --git a/packages/features/timezone-buddy/components/AvailabilitySliderTable.tsx b/packages/features/timezone-buddy/components/AvailabilitySliderTable.tsxindex 2050589d9a4..a3ad8221c8f 100644--- a/packages/features/timezone-buddy/components/AvailabilitySliderTable.tsx+++ b/packages/features/timezone-buddy/components/AvailabilitySliderTable.tsx@@ -8,6 +8,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";import dayjs from "@calcom/dayjs";import { DataTable, DataTableToolbar } from "@calcom/features/data-table";import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants";+import { CURRENT_TIMEZONE } from "@calcom/lib/constants";import type { DateRange } from "@calcom/lib/date-ranges";import { useDebounce } from "@calcom/lib/hooks/useDebounce";import { useLocale } from "@calcom/lib/hooks/useLocale";@@ -78,7 +79,7 @@ export function AvailabilitySliderTable(props: { userTimeFormat: number | null;const { data, isPending, fetchNextPage, isFetching } = trpc.viewer.availability.listTeam.useInfiniteQuery({limit: 10,- loggedInUsersTz: dayjs.tz.guess() || "Europe/London",+ loggedInUsersTz: CURRENT_TIMEZONE,startDate: browsingDate.startOf("day").toISOString(),endDate: browsingDate.endOf("day").toISOString(),searchString: debouncedSearchString,diff --git a/packages/lib/constants.ts b/packages/lib/constants.tsindex 95a6db6ff4d..b87396279c3 100644--- a/packages/lib/constants.ts+++ b/packages/lib/constants.ts@@ -65,6 +65,8 @@ export const HOSTED_CAL_FEATURES = process.env.NEXT_PUBLIC_HOSTED_CAL_FEATURES |export const IS_EUROPE = dayjs.tz.guess()?.indexOf("Europe") !== -1;+export const CURRENT_TIMEZONE = dayjs.tz.guess() !== "Etc/Unknown" ? dayjs.tz.guess() : "Europe/London";+/** @deprecated use `WEBAPP_URL` */export const NEXT_PUBLIC_BASE_URL = process.env.NEXT_PUBLIC_WEBAPP_URL || `https://${process.env.VERCEL_URL}`;export const LOGO = "/calcom-logo-white-word.svg";diff --git a/packages/platform/atoms/event-types/payments/PaymentForm.tsx b/packages/platform/atoms/event-types/payments/PaymentForm.tsxindex 73d9d4befa8..bb3f8411c62 100644--- a/packages/platform/atoms/event-types/payments/PaymentForm.tsx+++ b/packages/platform/atoms/event-types/payments/PaymentForm.tsx@@ -5,7 +5,7 @@ import dayjs from "@calcom/dayjs";import { PayIcon } from "@calcom/features/bookings/components/event-meta/PayIcon";import { Price } from "@calcom/features/bookings/components/event-meta/Price";import type { PaymentPageProps } from "@calcom/features/ee/payments/pages/payment";-import { APP_NAME, WEBSITE_URL } from "@calcom/lib/constants";+import { APP_NAME, WEBSITE_URL, CURRENT_TIMEZONE } from "@calcom/lib/constants";import getPaymentAppData from "@calcom/lib/getPaymentAppData";import { useLocale } from "@calcom/lib/hooks/useLocale";import { isBrowserLocale24h } from "@calcom/lib/timeFormat";@@ -40,8 +40,7 @@ export const PaymentForm = ({const eventName = paymentInfo?.booking.title;const is24h = isBrowserLocale24h();- const timezone =- localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess() || "Europe/London";+ const timezone = localStorage.getItem("timeOption.preferredTimeZone") || CURRENT_TIMEZONE;const date = dayjs.utc(paymentInfo?.booking.startTime).tz(timezone);if (isLoading) return <h1 className="p-4 pt-4 text-xl">Loading...</h1>;