From 605f7d35ec6a83cb1ce2b5ab1fe584dd1b4ff2ed Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Thu, 13 Jul 2023 02:32:11 +0200 Subject: [PATCH] fix: Ensure rendering as UTC to prevent browser tz from messing up times ## What does this PR do? Fixes all date shifts that are due browser time, by ensuring everything is UTC so it's not transformed to different times. The times weren't actually shifting, dates were, but after casting these to UTC properly the times were also shifting; so that was a bug after a bugfix, time wise it was only a problem to determine all day events (which didn't completely work) ### Yes, but how do I test this? Before: Create a all day date override in +05:30 Shift your local system time to -04:00 Note that the day is different After - do the same: The day is the same! Fixes #8365 Fixes #6978 Fixes #6482 --- apps/web/pages/availability/[schedule].tsx | 7 ++++--- .../components/DateOverrideInputDialog.tsx | 14 +++++++------- .../schedules/components/DateOverrideList.tsx | 1 + 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/apps/web/pages/availability/[schedule].tsx b/apps/web/pages/availability/[schedule].tsx index a4fdac00fc..5be10e58d0 100644 --- a/apps/web/pages/availability/[schedule].tsx +++ b/apps/web/pages/availability/[schedule].tsx @@ -3,11 +3,11 @@ import { useState } from "react"; import { Controller, useFieldArray, useForm } from "react-hook-form"; import { z } from "zod"; +import dayjs from "@calcom/dayjs"; import { DateOverrideInputDialog, DateOverrideList } from "@calcom/features/schedules"; import Schedule from "@calcom/features/schedules/components/Schedule"; import Shell from "@calcom/features/shell/Shell"; import { availabilityAsString } from "@calcom/lib/availability"; -import { yyyymmdd } from "@calcom/lib/date-fns"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery"; import { HttpError } from "@calcom/lib/http-error"; @@ -56,6 +56,7 @@ const DateOverride = ({ workingHours }: { workingHours: WorkingHours[] }) => { const { remove, append, update, fields } = useFieldArray({ name: "dateOverrides", }); + const excludedDates = fields.map((field) => dayjs(field.ranges[0].start).utc().format("YYYY-MM-DD")); const { t } = useLocale(); return (
@@ -70,7 +71,7 @@ const DateOverride = ({ workingHours }: { workingHours: WorkingHours[] }) => {

{t("date_overrides_subtitle")}

yyyymmdd(field.ranges[0].start))} + excludedDates={excludedDates} remove={remove} update={update} items={fields} @@ -78,7 +79,7 @@ const DateOverride = ({ workingHours }: { workingHours: WorkingHours[] }) => { /> yyyymmdd(field.ranges[0].start))} + excludedDates={excludedDates} onChange={(ranges) => append({ ranges })} Trigger={