Bugfix/year change (#1323)
This commit is contained in:
1 parent
e6f71c81bb
commit
a3bd226347
6 files changed
+132
-110
No files matched your search
+1
-1
@@ -79,7 +79,7 @@ export function getWorkingHours(
|
||||
];
|
||||
}
|
||||
|
||||
const utcOffset = relativeTimeUnit.utcOffset || dayjs().tz(relativeTimeUnit.timeZone).utcOffset();
|
||||
const utcOffset = relativeTimeUnit.utcOffset ?? dayjs().tz(relativeTimeUnit.timeZone).utcOffset();
|
||||
|
||||
const workingHours = availability.reduce((workingHours: WorkingHours[], schedule) => {
|
||||
// Get times localised to the given utcOffset/timeZone
|
||||
|
||||
@@ -107,7 +107,6 @@ export const useSlots = (props: UseSlotsProps) => {
|
||||
workingHours: responseBody.workingHours,
|
||||
minimumBookingNotice,
|
||||
});
|
||||
|
||||
// Check for conflicts
|
||||
for (let i = times.length - 1; i >= 0; i -= 1) {
|
||||
responseBody.busy.every((busyTime): boolean => {
|
||||
|
||||
+11
-11
@@ -19,7 +19,7 @@ export type GetSlots = {
|
||||
|
||||
const getMinuteOffset = (date: Dayjs, step: 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().startOf("day"), "minute"), 1440) % 1440;
|
||||
const minuteOffset = Math.min(date.diff(dayjs.utc().startOf("day"), "minute"), 1440) % 1440;
|
||||
// round down to nearest step
|
||||
return Math.ceil(minuteOffset / step) * step;
|
||||
};
|
||||
@@ -27,15 +27,11 @@ const getMinuteOffset = (date: Dayjs, step: number) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const getSlots = ({ inviteeDate, frequency, minimumBookingNotice, workingHours }: GetSlots) => {
|
||||
// current date in invitee tz
|
||||
let startDate = dayjs(inviteeDate); // .add(minimumBookingNotice, "minute");
|
||||
const startDate = dayjs().add(minimumBookingNotice, "minute");
|
||||
// checks if the start date is in the past
|
||||
if (startDate.isBefore(dayjs(), "day")) {
|
||||
if (inviteeDate.isBefore(startDate, "day")) {
|
||||
return [];
|
||||
}
|
||||
// Add the current time to the startDate if the day is today
|
||||
if (startDate.isToday()) {
|
||||
startDate = startDate.add(dayjs().diff(startDate, "minute"), "minute");
|
||||
}
|
||||
|
||||
const localWorkingHours = getWorkingHours(
|
||||
{ utcOffset: -inviteeDate.utcOffset() },
|
||||
@@ -47,14 +43,18 @@ const getSlots = ({ inviteeDate, frequency, minimumBookingNotice, workingHours }
|
||||
).filter((hours) => hours.days.includes(inviteeDate.day()));
|
||||
|
||||
const slots: Dayjs[] = [];
|
||||
for (let minutes = getMinuteOffset(startDate, frequency); minutes < 1440; minutes += frequency) {
|
||||
const slot = startDate.startOf("day").add(minutes, "minute");
|
||||
for (let minutes = getMinuteOffset(inviteeDate, frequency); minutes < 1440; minutes += frequency) {
|
||||
const slot = dayjs(inviteeDate).startOf("day").add(minutes, "minute");
|
||||
// check if slot happened already
|
||||
if (slot.isBefore(startDate)) {
|
||||
continue;
|
||||
}
|
||||
// add slots to available slots if it is found to be between the start and end time of the checked working hours.
|
||||
if (
|
||||
localWorkingHours.some((hours) =>
|
||||
slot.isBetween(
|
||||
startDate.startOf("day").add(hours.startTime, "minute"),
|
||||
startDate.startOf("day").add(hours.endTime, "minute"),
|
||||
inviteeDate.startOf("day").add(hours.startTime, "minute"),
|
||||
inviteeDate.startOf("day").add(hours.endTime, "minute"),
|
||||
null,
|
||||
"[)"
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user