Revert to local timezone display for user-facing times
- Changed formatTime back to use toLocaleTimeString (local time) - Changed formatDateTime back to use toLocaleString (local time) - App now displays all times in user's local timezone - Backend still stores times in UTC, frontend converts for display
This commit is contained in:
parent
a5b941e748
commit
74ed6f0c11
3 changed files with 30 additions and 24 deletions
|
|
@ -13,35 +13,30 @@ export function formatDate(d: Date): string {
|
|||
}
|
||||
|
||||
/**
|
||||
* Format time from ISO string to HH:MM format in UTC.
|
||||
* Uses UTC to avoid timezone conversion issues when displaying booking slots.
|
||||
* Format time from ISO string to HH:MM format in local timezone.
|
||||
*/
|
||||
export function formatTime(isoString: string): string {
|
||||
const d = new Date(isoString);
|
||||
// Use UTC methods to avoid timezone conversion
|
||||
const hours = String(d.getUTCHours()).padStart(2, "0");
|
||||
const minutes = String(d.getUTCMinutes()).padStart(2, "0");
|
||||
return `${hours}:${minutes}`;
|
||||
return d.toLocaleTimeString("en-US", {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
hour12: false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Format datetime from ISO string to a readable format in UTC.
|
||||
* Uses UTC to avoid timezone conversion issues when displaying appointment times.
|
||||
* Format datetime from ISO string to a readable format in local timezone.
|
||||
*/
|
||||
export function formatDateTime(isoString: string): string {
|
||||
const d = new Date(isoString);
|
||||
|
||||
// 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}`;
|
||||
return d.toLocaleString("en-US", {
|
||||
weekday: "short",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
hour12: false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue