Fix/incorrect timezone on booking success (#7544)

* set the selected timezone to formatToLocalizedTimezone function

* remove console.logs
pull/7553/head
Efraín Rochín 2023-03-06 16:12:43 -07:00 committed by GitHub
parent 69808bb9a4
commit 33f35e77fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -796,7 +796,6 @@ export function RecurringBookings({
t, t,
i18n: { language }, i18n: { language },
} = useLocale(); } = useLocale();
const recurringBookingsSorted = recurringBookings const recurringBookingsSorted = recurringBookings
? recurringBookings.sort((a: ConfigType, b: ConfigType) => (dayjs(a).isAfter(dayjs(b)) ? 1 : -1)) ? recurringBookings.sort((a: ConfigType, b: ConfigType) => (dayjs(a).isAfter(dayjs(b)) ? 1 : -1))
: null; : null;
@ -823,7 +822,7 @@ export function RecurringBookings({
{formatToLocalizedTime(dayjs(dateStr), language, undefined, !is24h)} -{" "} {formatToLocalizedTime(dayjs(dateStr), language, undefined, !is24h)} -{" "}
{formatToLocalizedTime(dayjs(dateStr).add(duration, "m"), language, undefined, !is24h)}{" "} {formatToLocalizedTime(dayjs(dateStr).add(duration, "m"), language, undefined, !is24h)}{" "}
<span className="text-bookinglight"> <span className="text-bookinglight">
({formatToLocalizedTimezone(dayjs(dateStr), language)}) ({formatToLocalizedTimezone(dayjs(dateStr), language, timeZone())})
</span> </span>
</div> </div>
))} ))}
@ -843,7 +842,7 @@ export function RecurringBookings({
{formatToLocalizedTime(date, language, undefined, !is24h)} -{" "} {formatToLocalizedTime(date, language, undefined, !is24h)} -{" "}
{formatToLocalizedTime(dayjs(date).add(duration, "m"), language, undefined, !is24h)}{" "} {formatToLocalizedTime(dayjs(date).add(duration, "m"), language, undefined, !is24h)}{" "}
<span className="text-bookinglight"> <span className="text-bookinglight">
({formatToLocalizedTimezone(dayjs(dateStr), language)}) ({formatToLocalizedTimezone(dayjs(dateStr), language, timeZone())})
</span> </span>
</div> </div>
))} ))}
@ -860,7 +859,7 @@ export function RecurringBookings({
<br /> <br />
{formatToLocalizedTime(date, language, undefined, !is24h)} -{" "} {formatToLocalizedTime(date, language, undefined, !is24h)} -{" "}
{formatToLocalizedTime(dayjs(date).add(duration, "m"), language, undefined, !is24h)}{" "} {formatToLocalizedTime(dayjs(date).add(duration, "m"), language, undefined, !is24h)}{" "}
<span className="text-bookinglight">({formatToLocalizedTimezone(date, language)})</span> <span className="text-bookinglight">({formatToLocalizedTimezone(date, language, timeZone())})</span>
</div> </div>
); );
} }

View File

@ -75,12 +75,13 @@ export const formatToLocalizedTime = (
export const formatToLocalizedTimezone = ( export const formatToLocalizedTimezone = (
date: Date | Dayjs, date: Date | Dayjs,
locale: string | undefined = undefined, locale: string | undefined = undefined,
timeZone: Intl.DateTimeFormatOptions["timeZone"],
timeZoneName: Intl.DateTimeFormatOptions["timeZoneName"] = "long" timeZoneName: Intl.DateTimeFormatOptions["timeZoneName"] = "long"
) => { ) => {
// Intl.DateTimeFormat doesn't format into a timezone only, so we must // Intl.DateTimeFormat doesn't format into a timezone only, so we must
// formatToParts() and return the piece we want // formatToParts() and return the piece we want
const theDate = date instanceof dayjs ? (date as Dayjs).toDate() : (date as Date); const theDate = date instanceof dayjs ? (date as Dayjs).toDate() : (date as Date);
return Intl.DateTimeFormat(locale, { timeZoneName }) return Intl.DateTimeFormat(locale, { timeZoneName, timeZone })
.formatToParts(theDate) .formatToParts(theDate)
.find((d) => d.type == "timeZoneName")?.value; .find((d) => d.type == "timeZoneName")?.value;
}; };