Skip to content

fix: timezone dependent unit test fail when not on utc #15377

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

Closed
Show file tree
Hide file tree
Changes from all 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 @@ -56,14 +56,16 @@ describe("handleNewBooking", () => {
});

// Using .endOf("day") here to ensure our date doesn't change when we set the time zone
const startDateTimeOrganizerTz = dayjs(plus1DateString)
const startDateTimeOrganizerTz = dayjs
.utc(plus1DateString)
.endOf("day")
.tz(newYorkTimeZone)
.hour(11)
.minute(0)
.second(0);

const endDateTimeOrganizerTz = dayjs(plus1DateString)
const endDateTimeOrganizerTz = dayjs
.utc(plus1DateString)
.endOf("day")
.tz(newYorkTimeZone)
.hour(12)
Expand Down Expand Up @@ -217,14 +219,16 @@ describe("handleNewBooking", () => {
});

// Using .endOf("day") here to ensure our date doesn't change when we set the time zone
const startDateTimeOrganizerTz = dayjs(plus1DateString)
const startDateTimeOrganizerTz = dayjs
.utc(plus1DateString)
.endOf("day")
.tz(newYorkTimeZone)
.hour(23)
.minute(0)
.second(0);

const endDateTimeOrganizerTz = dayjs(plus1DateString)
const endDateTimeOrganizerTz = dayjs
.utc(plus1DateString)
.endOf("day")
.tz(newYorkTimeZone)
.startOf("day")
Expand Down
16 changes: 8 additions & 8 deletions packages/lib/date-ranges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ describe("processWorkingHours", () => {
// in America/New_York DST ends on first Sunday of November
const timeZone = "America/New_York";

let firstSundayOfNovember = dayjs().startOf("day").month(10).date(1);
let firstSundayOfNovember = dayjs.utc().startOf("day").month(10).date(1);
while (firstSundayOfNovember.day() !== 0) {
firstSundayOfNovember = firstSundayOfNovember.add(1, "day");
}

const dateFrom = dayjs().month(10).date(1).startOf("day");
const dateTo = dayjs().month(10).endOf("month");
const dateFrom = dayjs.utc().month(10).date(1).startOf("day");
const dateTo = dayjs.utc().month(10).endOf("month");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using dayjs.utc to avoid change of date ( incremented to next day )
while using dayjs.endOf in certain timezones


const results = processWorkingHours({ item, timeZone, dateFrom, dateTo, travelSchedules: [] });

Expand Down Expand Up @@ -223,17 +223,17 @@ describe("processWorkingHours", () => {

const timeZone = "Europe/Berlin";

const dateFrom = dayjs().startOf("day");
const dateTo = dayjs().add(1, "week").startOf("day");
const dateFrom = dayjs.utc().startOf("day");
const dateTo = dayjs.utc().add(1, "week").startOf("day");

const travelSchedules = [
{
startDate: dayjs().add(2, "day").startOf("day"),
endDate: dayjs().add(3, "day").endOf("day"),
startDate: dayjs.utc().add(2, "day").startOf("day"),
endDate: dayjs.utc().add(3, "day").endOf("day"),
timeZone: "America/New_York",
},
{
startDate: dayjs().add(5, "day").startOf("day"),
startDate: dayjs.utc().add(5, "day").startOf("day"),
timeZone: "Asia/Kolkata",
},
];
Expand Down
2 changes: 1 addition & 1 deletion packages/prisma/zod-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export const stringOrNumber = z.union([
export const stringToDayjs = (val: string) => {
const matches = val.match(/([+-]\d{2}:\d{2})$/);
const timezone = matches ? matches[1] : "+00:00";
return dayjs(val).utcOffset(timezone);
return dayjs.utc(val).utcOffset(timezone);
};

export const stringToDayjsZod = z.string().transform(stringToDayjs);
Expand Down
Loading