Fixes: Get minutes offset from start of the day over days.utc() (#1488)

* Use days start of the day offset minutes over days.utc()

* We do not need to set startOf("day") as day.utc() already starts from the beginning of the day with respective +h value

* do not use startOf if the invite date is already set with utc value, otherwise, it will double the utc +h * 2

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
pull/1537/head^2
Manjunath Reddy 2022-01-18 04:15:19 +08:00 committed by GitHub
parent 103877737e
commit 2289c68979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -17,11 +17,11 @@ export type GetSlots = {
minimumBookingNotice: number;
};
const getMinuteOffset = (date: Dayjs, step: number) => {
const getMinuteOffset = (date: Dayjs, frequency: number) => {
// Diffs the current time with the given date and iff same day; (handled by 1440) - return difference; otherwise 0
const minuteOffset = Math.min(date.diff(dayjs.utc().startOf("day"), "minute"), 1440) % 1440;
const minuteOffset = Math.min(date.diff(dayjs().utc(), "minute"), 1440) % 1440;
// round down to nearest step
return Math.ceil(minuteOffset / step) * step;
return Math.ceil(minuteOffset / frequency) * frequency;
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars

View File

@ -16,7 +16,7 @@ it("can fit 24 hourly slots for an empty day", async () => {
// 24h in a day.
expect(
getSlots({
inviteeDate: dayjs.utc().add(1, "day").startOf("day"),
inviteeDate: dayjs.utc().add(1, "day"),
frequency: 60,
minimumBookingNotice: 0,
workingHours: [