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

pull/10430/head
Alex van Andel 2023-08-02 18:53:19 +01:00 committed by GitHub
parent 23f97bdd3c
commit 95dee6dd37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

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");
}