Skip to content

fix: wrong dates on OOO due to summer time #20408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ export const CreateOrEditOutOfOfficeEntryModal = ({
startDate: dayjs().startOf("d").toDate(),
endDate: dayjs().startOf("d").add(2, "d").toDate(),
},
offset: dayjs().utcOffset(),
startDateOffset: dayjs().utcOffset(),
endDateOffset: dayjs().utcOffset(),
toTeamUserId: null,
reasonId: 1,
forUserId: null,
Expand Down Expand Up @@ -194,7 +195,11 @@ export const CreateOrEditOutOfOfficeEntryModal = ({
if (!data.dateRange.endDate) {
showToast(t("end_date_not_selected"), "error");
} else {
createOrEditOutOfOfficeEntry.mutate(data);
createOrEditOutOfOfficeEntry.mutate({
...data,
startDateOffset: -1 * data.dateRange.startDate.getTimezoneOffset(),
endDateOffset: -1 * data.dateRange.endDate.getTimezoneOffset(),
});
}
})}>
<div className="h-full px-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
throw new TRPCError({ code: "BAD_REQUEST", message: "start_date_and_end_date_required" });
}

const startTimeUtc = dayjs.utc(startDate).add(input.offset, "minute").startOf("day");
const endTimeUtc = dayjs.utc(endDate).add(input.offset, "minute").endOf("day");
const startTimeUtc = dayjs.utc(startDate).add(input.startDateOffset, "minute").startOf("day");
const endTimeUtc = dayjs.utc(endDate).add(input.endDateOffset, "minute").endOf("day");

// If start date is after end date throw error
if (startTimeUtc.isAfter(endTimeUtc)) {
Expand Down Expand Up @@ -120,7 +120,7 @@
OR: [
// Outside of range
{
AND: [{ start: { lte: endTimeUtc.toISOString() } }, { end: { gte: startTimeUtc.toISOString() } }],

Check failure on line 123 in packages/trpc/server/routers/viewer/ooo/outOfOfficeCreateOrUpdate.handler.ts

View workflow job for this annotation

GitHub Actions / Tests / Unit

RangeError: Invalid time value ❯ M.u.toISOString node_modules/dayjs/plugin/utc.js:1:1907 ❯ Module.outOfOfficeCreateOrUpdate packages/trpc/server/routers/viewer/ooo/outOfOfficeCreateOrUpdate.handler.ts:123:44 ❯ packages/trpc/server/routers/viewer/__tests__/outOfOffice.handler.test.ts:84:11

Check failure on line 123 in packages/trpc/server/routers/viewer/ooo/outOfOfficeCreateOrUpdate.handler.ts

View workflow job for this annotation

GitHub Actions / Tests / Unit

RangeError: Invalid time value ❯ M.u.toISOString node_modules/dayjs/plugin/utc.js:1:1907 ❯ Module.outOfOfficeCreateOrUpdate packages/trpc/server/routers/viewer/ooo/outOfOfficeCreateOrUpdate.handler.ts:123:44 ❯ packages/trpc/server/routers/viewer/__tests__/outOfOffice.handler.test.ts:84:11

Check failure on line 123 in packages/trpc/server/routers/viewer/ooo/outOfOfficeCreateOrUpdate.handler.ts

View workflow job for this annotation

GitHub Actions / Tests / Unit

RangeError: Invalid time value ❯ M.u.toISOString node_modules/dayjs/plugin/utc.js:1:1907 ❯ Module.outOfOfficeCreateOrUpdate packages/trpc/server/routers/viewer/ooo/outOfOfficeCreateOrUpdate.handler.ts:123:44 ❯ packages/trpc/server/routers/viewer/__tests__/outOfOffice.handler.test.ts:84:11
},
// Inside of range
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const ZOutOfOfficeInputSchema = z.object({
startDate: z.date(),
endDate: z.date(),
}),
offset: z.number(),
startDateOffset: z.number(),
endDateOffset: z.number(),
toTeamUserId: z.number().nullable(),
reasonId: z.number(),
notes: z.string().nullable().optional(),
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/components/form/date-range-picker/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ function Calendar({
nav: "flex items-center",
head: "",
head_row: "flex w-full items-center justify-between",
head_cell: "w-8 md:w-11 h-8 text-sm font-medium text-default",
head_cell: "w-8 md:w-11 h-8 text-sm font-medium text-default text-center",
nav_button: cn(buttonClasses({ color: "minimal", variant: "icon" })),
table: "w-full border-collapse space-y-1",
row: "flex w-full mt-2 gap-0.5",
cell: "h-8 w-8 md:h-11 md:w-11 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20",
row: "flex w-full mt-0.5 gap-0.5",
cell: "w-8 h-8 md:h-11 md:w-11 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20",
day: cn(
buttonClasses({ color: "minimal" }),
"w-8 h-8 md:h-11 md:w-11 p-0 text-sm font-medium aria-selected:opacity-100 inline-flex items-center justify-center"
Expand Down
Loading