Fix timezone issue in formatDateTime for appointments page

- Changed formatDateTime to use UTC methods instead of toLocaleString
- Prevents timezone conversion when displaying appointment times
- Now booking at 11:45 shows as 11:45 in appointments page, not 12:45
- Consistent with formatTime which already uses UTC
- Manual formatting to match previous format: 'Mon, Jan 15, 11:45'
This commit is contained in:
counterweight 2025-12-21 18:18:40 +01:00
parent b900b52b3c
commit a5b941e748
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -25,18 +25,23 @@ export function formatTime(isoString: string): string {
} }
/** /**
* Format datetime from ISO string to a readable format. * Format datetime from ISO string to a readable format in UTC.
* Uses UTC to avoid timezone conversion issues when displaying appointment times.
*/ */
export function formatDateTime(isoString: string): string { export function formatDateTime(isoString: string): string {
const d = new Date(isoString); const d = new Date(isoString);
return d.toLocaleString("en-US", {
weekday: "short", // Use UTC methods to avoid timezone conversion
month: "short", const weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
day: "numeric", const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
hour: "2-digit",
minute: "2-digit", const weekday = weekdays[d.getUTCDay()];
hour12: false, const month = months[d.getUTCMonth()];
}); const day = d.getUTCDate();
const hours = String(d.getUTCHours()).padStart(2, "0");
const minutes = String(d.getUTCMinutes()).padStart(2, "0");
return `${weekday}, ${month} ${day}, ${hours}:${minutes}`;
} }
/** /**