From a5b941e7485bc32f011a10bbddf764f21aff4407 Mon Sep 17 00:00:00 2001 From: counterweight Date: Sun, 21 Dec 2025 18:18:40 +0100 Subject: [PATCH] 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' --- frontend/app/utils/date.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/frontend/app/utils/date.ts b/frontend/app/utils/date.ts index 56ebc06..2e34103 100644 --- a/frontend/app/utils/date.ts +++ b/frontend/app/utils/date.ts @@ -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 { const d = new Date(isoString); - return d.toLocaleString("en-US", { - weekday: "short", - month: "short", - day: "numeric", - hour: "2-digit", - minute: "2-digit", - hour12: false, - }); + + // Use UTC methods to avoid timezone conversion + const weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + + const weekday = weekdays[d.getUTCDay()]; + 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}`; } /**