perf: Use Intl.DateTimeFormat instead of Dayjs.tz().format() (#10604)
parent
359779cabb
commit
9a08fbb22d
|
@ -408,17 +408,27 @@ export async function getSchedule(input: TGetScheduleInputSchema) {
|
||||||
}
|
}
|
||||||
|
|
||||||
availableTimeSlots = availableTimeSlots.filter((slot) => isTimeWithinBounds(slot.time));
|
availableTimeSlots = availableTimeSlots.filter((slot) => isTimeWithinBounds(slot.time));
|
||||||
|
// fr-CA uses YYYY-MM-DD
|
||||||
|
const formatter = new Intl.DateTimeFormat("fr-CA", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "2-digit",
|
||||||
|
day: "2-digit",
|
||||||
|
timeZone: input.timeZone,
|
||||||
|
});
|
||||||
|
|
||||||
const computedAvailableSlots = availableTimeSlots.reduce(
|
const computedAvailableSlots = availableTimeSlots.reduce(
|
||||||
(
|
(
|
||||||
r: Record<string, { time: string; users: string[]; attendees?: number; bookingUid?: string }[]>,
|
r: Record<string, { time: string; users: string[]; attendees?: number; bookingUid?: string }[]>,
|
||||||
{ time: _time, ...passThroughProps }
|
{ time, ...passThroughProps }
|
||||||
) => {
|
) => {
|
||||||
// TODO: Adds unit tests to prevent regressions in getSchedule (try multiple timezones)
|
// TODO: Adds unit tests to prevent regressions in getSchedule (try multiple timezones)
|
||||||
const time = _time.tz(input.timeZone);
|
|
||||||
|
|
||||||
r[time.format("YYYY-MM-DD")] = r[time.format("YYYY-MM-DD")] || [];
|
// This used to be _time.tz(input.timeZone) but Dayjs tz() is slow.
|
||||||
r[time.format("YYYY-MM-DD")].push({
|
// toLocaleDateString slugish, using Intl.DateTimeFormat we get the desired speed results.
|
||||||
|
const dateString = formatter.format(time.toDate());
|
||||||
|
|
||||||
|
r[dateString] = r[dateString] || [];
|
||||||
|
r[dateString].push({
|
||||||
...passThroughProps,
|
...passThroughProps,
|
||||||
time: time.toISOString(),
|
time: time.toISOString(),
|
||||||
users: (eventType.hosts
|
users: (eventType.hosts
|
||||||
|
|
Loading…
Reference in New Issue