Uses utcOffset to display bookings according to current time & timeZone (#5050)
This commit is contained in:
1 parent
1aade4fc57
commit
68f05ce2c7
3 files changed
+83
-57
No files matched your search
@@ -206,6 +206,9 @@ function BookingListItem(booking: BookingItemProps) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const utcOffset = dayjs().tz(user?.timeZone).utcOffset();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<RescheduleDialog
|
<RescheduleDialog
|
||||||
@@ -258,12 +261,14 @@ function BookingListItem(booking: BookingItemProps) {
|
|||||||
<div className="cursor-pointer py-4">
|
<div className="cursor-pointer py-4">
|
||||||
<div className="text-sm leading-6 text-gray-900">{startTime}</div>
|
<div className="text-sm leading-6 text-gray-900">{startTime}</div>
|
||||||
<div className="text-sm text-gray-500">
|
<div className="text-sm text-gray-500">
|
||||||
{dayjs(booking.startTime)
|
{dayjs
|
||||||
.tz(user?.timeZone)
|
.utc(booking.startTime)
|
||||||
|
.utcOffset(utcOffset)
|
||||||
.format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")}{" "}
|
.format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")}{" "}
|
||||||
-{" "}
|
-{" "}
|
||||||
{dayjs(booking.endTime)
|
{dayjs
|
||||||
.tz(user?.timeZone)
|
.utc(booking.endTime)
|
||||||
|
.utcOffset(utcOffset)
|
||||||
.format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")}
|
.format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -299,12 +304,14 @@ function BookingListItem(booking: BookingItemProps) {
|
|||||||
<div className="flex w-full items-center justify-between sm:hidden">
|
<div className="flex w-full items-center justify-between sm:hidden">
|
||||||
<div className="text-sm leading-6 text-gray-900">{startTime}</div>
|
<div className="text-sm leading-6 text-gray-900">{startTime}</div>
|
||||||
<div className="pr-2 text-sm text-gray-500">
|
<div className="pr-2 text-sm text-gray-500">
|
||||||
{dayjs(booking.startTime)
|
{dayjs
|
||||||
.tz(user?.timeZone)
|
.utc(booking.startTime)
|
||||||
|
.utcOffset(utcOffset)
|
||||||
.format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")}{" "}
|
.format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")}{" "}
|
||||||
-{" "}
|
-{" "}
|
||||||
{dayjs(booking.endTime)
|
{dayjs
|
||||||
.tz(user?.timeZone)
|
.utc(booking.endTime)
|
||||||
|
.utcOffset(utcOffset)
|
||||||
.format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")}
|
.format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm")}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -39,10 +39,20 @@ export const parseRecurringDates = (
|
|||||||
const rule = new RRule({
|
const rule = new RRule({
|
||||||
...restRecurringEvent,
|
...restRecurringEvent,
|
||||||
count: recurringCount,
|
count: recurringCount,
|
||||||
dtstart: dayjs(startDate).toDate(),
|
dtstart: new Date(
|
||||||
|
Date.UTC(
|
||||||
|
dayjs.utc(startDate).get("year"),
|
||||||
|
dayjs.utc(startDate).get("month"),
|
||||||
|
dayjs.utc(startDate).get("date"),
|
||||||
|
dayjs.utc(startDate).get("hour"),
|
||||||
|
dayjs.utc(startDate).get("minute")
|
||||||
|
)
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const utcOffset = dayjs(startDate).tz(timeZone).utcOffset();
|
||||||
const dateStrings = rule.all().map((r) => {
|
const dateStrings = rule.all().map((r) => {
|
||||||
return processDate(dayjs(r).tz(timeZone), i18n);
|
return processDate(dayjs.utc(r).utcOffset(utcOffset), i18n);
|
||||||
});
|
});
|
||||||
return [dateStrings, rule.all()];
|
return [dateStrings, rule.all()];
|
||||||
};
|
};
|
||||||
@@ -66,8 +76,9 @@ export const extractRecurringDates = (
|
|||||||
count: recurringInfo?._count.recurringEventId,
|
count: recurringInfo?._count.recurringEventId,
|
||||||
dtstart: recurringInfo?._min.startTime,
|
dtstart: recurringInfo?._min.startTime,
|
||||||
}).all();
|
}).all();
|
||||||
|
const utcOffset = dayjs(recurringInfo?._min.startTime).tz(timeZone).utcOffset();
|
||||||
const dateStrings = allDates.map((r) => {
|
const dateStrings = allDates.map((r) => {
|
||||||
return processDate(dayjs(r).tz(timeZone), i18n);
|
return processDate(dayjs.utc(r).utcOffset(utcOffset), i18n);
|
||||||
});
|
});
|
||||||
return [dateStrings, allDates];
|
return [dateStrings, allDates];
|
||||||
};
|
};
|
||||||
+54
-46
@@ -620,52 +620,60 @@ export function RecurringBookings({
|
|||||||
? recurringBookings.sort((a, b) => (dayjs(a).isAfter(dayjs(b)) ? 1 : -1))
|
? recurringBookings.sort((a, b) => (dayjs(a).isAfter(dayjs(b)) ? 1 : -1))
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
return recurringBookingsSorted && listingStatus === "recurring" ? (
|
if (recurringBookingsSorted && listingStatus === "recurring") {
|
||||||
<>
|
// recurring bookings should only be adjusted to the start date.
|
||||||
{eventType.recurringEvent?.count && (
|
const utcOffset = dayjs(recurringBookingsSorted[0]).utcOffset();
|
||||||
<span className="font-medium">
|
return (
|
||||||
{getEveryFreqFor({
|
<>
|
||||||
t,
|
{eventType.recurringEvent?.count && (
|
||||||
recurringEvent: eventType.recurringEvent,
|
<span className="font-medium">
|
||||||
recurringCount: recurringBookings?.length ?? undefined,
|
{getEveryFreqFor({
|
||||||
})}
|
t,
|
||||||
</span>
|
recurringEvent: eventType.recurringEvent,
|
||||||
)}
|
recurringCount: recurringBookings?.length ?? undefined,
|
||||||
{eventType.recurringEvent?.count &&
|
})}
|
||||||
recurringBookingsSorted.slice(0, 4).map((dateStr, idx) => (
|
</span>
|
||||||
<div key={idx} className="mb-2">
|
)}
|
||||||
{dayjs(dateStr).format("MMMM DD, YYYY")}
|
{eventType.recurringEvent?.count &&
|
||||||
<br />
|
recurringBookingsSorted.slice(0, 4).map((dateStr, idx) => (
|
||||||
{dayjs(dateStr).format("LT")} - {dayjs(dateStr).add(eventType.length, "m").format("LT")}{" "}
|
<div key={idx} className="mb-2">
|
||||||
<span className="text-bookinglight">
|
{dayjs(dateStr).utcOffset(utcOffset).format("MMMM DD, YYYY")}
|
||||||
({localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()})
|
<br />
|
||||||
</span>
|
{dayjs(dateStr).utcOffset(utcOffset).format("LT")} -{" "}
|
||||||
</div>
|
{dayjs(dateStr).utcOffset(utcOffset).add(eventType.length, "m").format("LT")}{" "}
|
||||||
))}
|
<span className="text-bookinglight">
|
||||||
{recurringBookingsSorted.length > 4 && (
|
({localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()})
|
||||||
<Collapsible open={moreEventsVisible} onOpenChange={() => setMoreEventsVisible(!moreEventsVisible)}>
|
</span>
|
||||||
<CollapsibleTrigger
|
</div>
|
||||||
type="button"
|
))}
|
||||||
className={classNames("flex w-full", moreEventsVisible ? "hidden" : "")}>
|
{recurringBookingsSorted.length > 4 && (
|
||||||
{t("plus_more", { count: recurringBookingsSorted.length - 4 })}
|
<Collapsible open={moreEventsVisible} onOpenChange={() => setMoreEventsVisible(!moreEventsVisible)}>
|
||||||
</CollapsibleTrigger>
|
<CollapsibleTrigger
|
||||||
<CollapsibleContent>
|
type="button"
|
||||||
{eventType.recurringEvent?.count &&
|
className={classNames("flex w-full", moreEventsVisible ? "hidden" : "")}>
|
||||||
recurringBookingsSorted.slice(4).map((dateStr, idx) => (
|
{t("plus_more", { count: recurringBookingsSorted.length - 4 })}
|
||||||
<div key={idx} className="mb-2">
|
</CollapsibleTrigger>
|
||||||
{dayjs(dateStr).format("MMMM DD, YYYY")}
|
<CollapsibleContent>
|
||||||
<br />
|
{eventType.recurringEvent?.count &&
|
||||||
{dayjs(dateStr).format("LT")} - {dayjs(dateStr).add(eventType.length, "m").format("LT")}{" "}
|
recurringBookingsSorted.slice(4).map((dateStr, idx) => (
|
||||||
<span className="text-bookinglight">
|
<div key={idx} className="mb-2">
|
||||||
({localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()})
|
{dayjs(dateStr).utcOffset(utcOffset).format("MMMM DD, YYYY")}
|
||||||
</span>
|
<br />
|
||||||
</div>
|
{dayjs(dateStr).utcOffset(utcOffset).format("LT")} -{" "}
|
||||||
))}
|
{dayjs(dateStr).utcOffset(utcOffset).add(eventType.length, "m").format("LT")}{" "}
|
||||||
</CollapsibleContent>
|
<span className="text-bookinglight">
|
||||||
</Collapsible>
|
({localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()})
|
||||||
)}
|
</span>
|
||||||
</>
|
</div>
|
||||||
) : (
|
))}
|
||||||
|
</CollapsibleContent>
|
||||||
|
</Collapsible>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
<>
|
<>
|
||||||
{date.format("MMMM DD, YYYY")}
|
{date.format("MMMM DD, YYYY")}
|
||||||
<br />
|
<br />
|
||||||
|
|||||||
Reference in new issue
Block a user