perf: Turns out the tz() function is very slow, 4ms (#10545)

This commit is contained in:
Alex van Andel
2023-08-02 13:53:19 -04:00
committed by GitHub
parent 23f97bdd3c
commit 95dee6dd37
+7 -4
View File
@@ -165,7 +165,9 @@ function buildSlotsWithDateRanges({
dateRanges.forEach((range) => {
const startTimeWithMinNotice = dayjs.utc().add(minimumBookingNotice, "minute");
let slotStartTime = range.start.isAfter(startTimeWithMinNotice) ? range.start : startTimeWithMinNotice;
let slotStartTime = range.start.utc().isAfter(startTimeWithMinNotice)
? range.start
: startTimeWithMinNotice;
let interval = 15;
@@ -190,10 +192,11 @@ function buildSlotsWithDateRanges({
? range.end.add(1, "minute")
: range.end;
slotStartTime = slotStartTime.add(offsetStart ?? 0, "minutes");
while (!slotStartTime.add(eventLength, "minutes").subtract(1, "second").isAfter(rangeEnd)) {
slotStartTime = slotStartTime.add(offsetStart ?? 0, "minutes").tz(timeZone);
while (!slotStartTime.add(eventLength, "minutes").subtract(1, "second").utc().isAfter(rangeEnd)) {
slots.push({
time: slotStartTime.tz(timeZone),
time: slotStartTime,
});
slotStartTime = slotStartTime.add(frequency + (offsetStart ?? 0), "minutes");
}