Scheduling infrastructure for absolutely everyone.
perf: Improve performance of period limits (#20974)
Alex van Andeleacd05bf3b67
diff --git a/packages/lib/isOutOfBounds.tsx b/packages/lib/isOutOfBounds.tsxindex db2956fed51..43e5bc9c986 100644--- a/packages/lib/isOutOfBounds.tsx+++ b/packages/lib/isOutOfBounds.tsx@@ -268,51 +268,40 @@ export function isTimeViolatingFutureLimit({time,periodLimits,}: {- time: dayjs.ConfigType;+ time: string | Date | number;periodLimits: PeriodLimits;}) {const log = logger.getSubLogger({ prefix: ["isTimeViolatingFutureLimit"] });- // Because we are just going to compare times, we need not convert the time to a particular timezone- // date.isAfter/isBefore are timezone neutral- const dateInSystemTz = dayjs(time);++ const dateObj = new Date(time);if (periodLimits.endOfRollingPeriodEndDayInBookerTz) {- const isAfterRollingEndDay = dateInSystemTz.isAfter(periodLimits.endOfRollingPeriodEndDayInBookerTz);- log.silly("rollingEndDayCheck", {- formattedDate: dateInSystemTz.format(),- isAfterRollingEndDay,- endOfRollingPeriodEndDayInBookerTz: periodLimits.endOfRollingPeriodEndDayInBookerTz.format(),- });+ const isAfterRollingEndDay =+ dateObj.valueOf() > periodLimits.endOfRollingPeriodEndDayInBookerTz.valueOf();+if (isAfterRollingEndDay)log.warn("Booking is out of bounds due to rolling period end day.",safeStringify({- formattedDate: dateInSystemTz.format(),+ formattedDate: dateObj.toISOString(),isAfterRollingEndDay,- endOfRollingPeriodEndDayInBookerTz: periodLimits.endOfRollingPeriodEndDayInBookerTz.format(),+ endOfRollingPeriodEndDayTs: periodLimits.endOfRollingPeriodEndDayInBookerTz.valueOf(),}));return isAfterRollingEndDay;}if (periodLimits.startOfRangeStartDayInEventTz && periodLimits.endOfRangeEndDayInEventTz) {- const isBeforeRangeStart = dateInSystemTz.isBefore(periodLimits.startOfRangeStartDayInEventTz);- const isAfterRangeEnd = dateInSystemTz.isAfter(periodLimits.endOfRangeEndDayInEventTz);- log.silly("rangeCheck", {- formattedDate: dateInSystemTz.format(),- isAfterRangeEnd,- isBeforeRangeStart,- startOfRangeStartDayInEventTz: periodLimits.startOfRangeStartDayInEventTz.format(),- endOfRangeEndDayInEventTz: periodLimits.endOfRangeEndDayInEventTz.format(),- });+ const isBeforeRangeStart = dateObj.valueOf() < periodLimits.startOfRangeStartDayInEventTz.valueOf();+ const isAfterRangeEnd = dateObj.valueOf() > periodLimits.endOfRangeEndDayInEventTz.valueOf();if (isBeforeRangeStart || isAfterRangeEnd)log.warn("Booking is out of bounds due to range start and end.",safeStringify({- formattedDate: dateInSystemTz.format(),+ formattedDate: dateObj.toISOString(),isBeforeRangeStart,isAfterRangeEnd,- startOfRangeStartDayInEventTz: periodLimits.startOfRangeStartDayInEventTz.format(),- endOfRangeEndDayInEventTz: periodLimits.endOfRangeEndDayInEventTz.format(),+ startOfRangeStartDayInEventTz: periodLimits.startOfRangeStartDayInEventTz.toDate().toISOString(),+ endOfRangeEndDayInEventTz: periodLimits.endOfRangeEndDayInEventTz.toDate().toISOString(),}));return isBeforeRangeStart || isAfterRangeEnd;@@ -321,7 +310,7 @@ export function isTimeViolatingFutureLimit({}export default function isOutOfBounds(- time: dayjs.ConfigType,+ time: NonNullable<dayjs.ConfigType>,{periodType,periodDays,@@ -354,7 +343,7 @@ export default function isOutOfBounds(});const isOutOfBoundsByPeriod = isTimeViolatingFutureLimit({- time,+ time: dayjs.isDayjs(time) ? time.toDate() : time,periodLimits,});