Scheduling infrastructure for absolutely everyone.
Removed code bloat, fixed tests
Alex van Andel0da99f0d078a
diff --git a/.babelrc b/.babelrcnew file mode 100644index 00000000000..e49a7e6569d--- /dev/null+++ b/.babelrc@@ -0,0 +1,3 @@+{+ "presets": ["next/babel"]+}\ No newline at end of filediff --git a/components/ui/modal/DateOverrideModal.tsx b/components/ui/modal/DateOverrideModal.tsxdeleted file mode 100644index 282f6125907..00000000000--- a/components/ui/modal/DateOverrideModal.tsx+++ /dev/null@@ -1,7 +0,0 @@---/*export default function DateOverrideModal(props) {- return (-- );-}*/\ No newline at end of filediff --git a/lib/slots.ts b/lib/slots.tsindex 7d3a777373d..c82913b5972 100644--- a/lib/slots.ts+++ b/lib/slots.ts@@ -4,20 +4,20 @@ import timezone from "dayjs/plugin/timezone";dayjs.extend(utc);dayjs.extend(timezone);-interface GetSlotsType {+type GetSlots = {inviteeDate: Dayjs;frequency: number;workingHours: [];minimumBookingNotice?: number;- organizerUtcOffset: number;-}+ organizerTimeZone: string;+};-interface Boundary {+type Boundary = {lowerBound: number;upperBound: number;-}+};-const freqApply: number = (cb, value: number, frequency: number): number => cb(value / frequency) * frequency;+const freqApply = (cb, value: number, frequency: number): number => cb(value / frequency) * frequency;const intersectBoundary = (a: Boundary, b: Boundary) => {if (a.upperBound < b.lowerBound || a.lowerBound > b.upperBound) {@@ -108,12 +108,13 @@ const getSlots = ({minimumBookingNotice,workingHours,organizerTimeZone,-}: GetSlotsType): Dayjs[] => {+}: GetSlots): Dayjs[] => {const startTime = dayjs.utc().isSame(dayjs(inviteeDate), "day")? inviteeDate.hour() * 60 + inviteeDate.minute() + minimumBookingNotice: 0;const inviteeBounds = inviteeBoundary(startTime, inviteeDate.utcOffset(), frequency);+return getOverlaps(inviteeBounds,organizerBoundaries(workingHours, inviteeDate, inviteeBounds, organizerTimeZone)diff --git a/test/lib/slots.test.ts b/test/lib/slots.test.tsindex 90bec4be3bf..82788371731 100644--- a/test/lib/slots.test.ts+++ b/test/lib/slots.test.ts@@ -13,27 +13,10 @@ it('can fit 24 hourly slots for an empty day', async () => {// 24h in a day.expect(getSlots({inviteeDate: dayjs().add(1, 'day'),- length: 60,+ frequency: 60,+ workingHours: [+ { days: [...Array(7).keys()], startTime: 0, endTime: 1440 }+ ],+ organizerTimeZone: 'Europe/London'})).toHaveLength(24);-});--it('has slots that be in the same timezone as the invitee', async() => {- expect(getSlots({- inviteeDate: dayjs().add(1, 'day'),- length: 60- })[0].utcOffset()).toBe(-0);-- expect(getSlots({- inviteeDate: dayjs().tz('Europe/London').add(1, 'day'),- length: 60- })[0].utcOffset()).toBe(dayjs().tz('Europe/London').utcOffset());-})--it('excludes slots that have already passed when invitee day equals today', async () => {- expect(getSlots({ inviteeDate: dayjs(), length: 60 })).toHaveLength(12);-});--it('supports having slots in different utc offset than the invitee', async () => {- expect(getSlots({ inviteeDate: dayjs(), length: 60 })).toHaveLength(12);- expect(getSlots({ inviteeDate: dayjs().tz('Europe/Brussels'), length: 60 })).toHaveLength(14);});\ No newline at end of file