mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 13:01:00 +00:00
chore(charts): align chart-tick timezone handling across the chart surface
Audits the chart-tick timezone contract called out in BL-P4-2. `sleep-stage-stacked-bar`, `mood-chart`, `health-chart`, and `medication-compliance-chart` already anchor every day-key construction at `Date.UTC(y, m - 1, d)` and route tick rendering through the timezone-aware formatter pair (`tzFmt.date` / `tzFmt.dateShort`), so they audit clean. The compliance heatmap was the outlier: the day cells walked the weekday and month-boundary axes with `getDay()` and `getMonth()`, which read in the SSR server's local timezone while the dateKey above used `toISOString().slice(0, 10)` (UTC). An SSR pass running on a non-Berlin host would land the Monday alignment and the month markers one position off relative to the cells they sit under. Swapped to the UTC accessor pair so all three coordinates (dateKey, weekday row, month-marker label) read off the same clock. The tooltip date formatter also parsed the day-key against local time; pinned to `T00:00:00Z` + the UTC accessor trio for the same reason.
This commit is contained in:
1 parent
f72d2de27c
commit
d10e0f287b
1 file changed
+18
-6
@@ -57,8 +57,13 @@ function getColor(data: DailyData): string {
|
||||
}
|
||||
|
||||
function formatDateDE(dateStr: string): string {
|
||||
const d = new Date(dateStr + "T00:00:00");
|
||||
return `${d.getDate()}.${d.getMonth() + 1}.${d.getFullYear()}`;
|
||||
// v1.4.27 B7 / BL-P4-2 — parse the day-key against UTC so the
|
||||
// formatted tooltip label matches the dateKey computation below
|
||||
// (which uses `toISOString().slice(0, 10)`). Without the UTC
|
||||
// anchor an SSR server in a non-Berlin timezone could format the
|
||||
// tick a day off the dateKey it sits under.
|
||||
const d = new Date(dateStr + "T00:00:00Z");
|
||||
return `${d.getUTCDate()}.${d.getUTCMonth() + 1}.${d.getUTCFullYear()}`;
|
||||
}
|
||||
|
||||
export function ComplianceHeatmap({
|
||||
@@ -133,9 +138,16 @@ export function ComplianceHeatmap({
|
||||
dates.push(date);
|
||||
}
|
||||
|
||||
// Start from the first date, align to Monday
|
||||
// Start from the first date, align to Monday.
|
||||
//
|
||||
// v1.4.27 B7 / BL-P4-2 — read every weekday + month boundary off
|
||||
// the UTC accessor pair (`getUTCDay`, `getUTCMonth`) so the
|
||||
// computation matches the dateKey, which is also UTC-anchored
|
||||
// (`toISOString().slice(0, 10)`). Reading in server-tz here would
|
||||
// shift the Monday-alignment + month-marker placement when the
|
||||
// SSR pass runs on a server in a non-Berlin timezone.
|
||||
const firstDate = dates[0];
|
||||
const firstDow = (firstDate.getDay() + 6) % 7; // Monday = 0
|
||||
const firstDow = (firstDate.getUTCDay() + 6) % 7; // Monday = 0
|
||||
|
||||
let col = 0;
|
||||
const markers: Array<{ col: number; label: string }> = [];
|
||||
@@ -143,7 +155,7 @@ export function ComplianceHeatmap({
|
||||
|
||||
for (let i = 0; i < dates.length; i++) {
|
||||
const date = dates[i];
|
||||
const dow = (date.getDay() + 6) % 7; // Monday = 0
|
||||
const dow = (date.getUTCDay() + 6) % 7; // Monday = 0
|
||||
const currentCol = Math.floor((i + firstDow) / 7);
|
||||
const row = dow;
|
||||
const dateKey = date.toISOString().slice(0, 10);
|
||||
@@ -154,7 +166,7 @@ export function ComplianceHeatmap({
|
||||
};
|
||||
|
||||
// Track month boundaries
|
||||
const month = date.getMonth();
|
||||
const month = date.getUTCMonth();
|
||||
if (month !== lastMonth) {
|
||||
markers.push({ col: currentCol, label: MONTH_LABELS[month] });
|
||||
lastMonth = month;
|
||||
|
||||
Reference in new issue
Block a user