Add timezone preference and fix all date handling to be timezone-aware
Build and push image / build (push) Successful in 56s
Build and push image / build (push) Successful in 56s
Dates were computed using browser/server local time with no explicit timezone, causing inconsistencies when server runs in UTC. Now all "today" computations and date formatting use the user's chosen IANA timezone, persisted in localStorage and selectable from Settings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
export const TZ_STORAGE_KEY = "apothecary.timezone";
|
||||
|
||||
const enCA = (tz: string) =>
|
||||
new Intl.DateTimeFormat("en-CA", {
|
||||
timeZone: tz,
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
});
|
||||
|
||||
export function getToday(tz: string): string {
|
||||
return enCA(tz).format(new Date());
|
||||
}
|
||||
|
||||
export function getBrowserTimezone(): string {
|
||||
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
}
|
||||
|
||||
export function getStoredTimezone(): string {
|
||||
return localStorage.getItem(TZ_STORAGE_KEY) || getBrowserTimezone();
|
||||
}
|
||||
Reference in New Issue
Block a user