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:
parent
b900b52b3c
commit
a5b941e748
1 changed files with 14 additions and 9 deletions
|
|
@ -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}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue