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:
+12
-4
@@ -4,7 +4,8 @@
|
||||
// stay clean). Operates on the enriched Item[] view, not raw products.
|
||||
|
||||
import type { Bootstrap, Item } from "./types.js";
|
||||
import { TYPES, TODAY_STR, helpers, enrichItems } from "./types.js";
|
||||
import { TYPES, helpers, enrichItems } from "./types.js";
|
||||
import { getToday, getStoredTimezone } from "./tz.js";
|
||||
|
||||
export interface Stats {
|
||||
dailyAvg: number;
|
||||
@@ -49,10 +50,17 @@ export interface Stats {
|
||||
}
|
||||
|
||||
export function computeStats(data: Bootstrap): Stats {
|
||||
const today = new Date(data.today || TODAY_STR);
|
||||
const todayStr = today.toISOString().slice(0, 10);
|
||||
const tz = getStoredTimezone();
|
||||
const todayStr = getToday(tz);
|
||||
const today = new Date(todayStr + "T12:00:00");
|
||||
const items = enrichItems(data);
|
||||
const dayKey = (d: Date) => d.toISOString().slice(0, 10);
|
||||
const dayKeyFmt = new Intl.DateTimeFormat("en-CA", {
|
||||
timeZone: tz,
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
});
|
||||
const dayKey = (d: Date) => dayKeyFmt.format(d);
|
||||
|
||||
const active = items.filter((p) => p.status === "active" || p.status === "checked-out");
|
||||
const consumed = items.filter((p) => p.status === "consumed" && p.consumedDate);
|
||||
|
||||
Reference in New Issue
Block a user