Fix week nav arrows — use local date string to avoid BST offset bug

toISOString() returns UTC, so midnight local in BST (UTC+1) lands on
the previous UTC day, making each arrow step 6 days instead of 7.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-20 13:45:50 +00:00
parent 8da7e46d72
commit 4744e74dfa

View file

@ -31,19 +31,22 @@ const MONTH_NAMES = ['January','February','March','April','May','June','July','A
// ── Week navigation ──────────────────────────────────────────────────────── // ── Week navigation ────────────────────────────────────────────────────────
function localDateStr(d: Date): string {
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
}
function defaultWeekEnding(): string { function defaultWeekEnding(): string {
const d = new Date() const d = new Date()
const day = d.getDay() const day = d.getDay()
// Go back to the most recent Saturday (day=6→today, else go back)
const daysBack = day === 6 ? 0 : day + 1 const daysBack = day === 6 ? 0 : day + 1
d.setDate(d.getDate() - daysBack) d.setDate(d.getDate() - daysBack)
return d.toISOString().split('T')[0] return localDateStr(d)
} }
function shiftWeek(dateStr: string, weeks: number): string { function shiftWeek(dateStr: string, weeks: number): string {
const d = new Date(dateStr + 'T00:00:00') const d = new Date(dateStr + 'T00:00:00')
d.setDate(d.getDate() + weeks * 7) d.setDate(d.getDate() + weeks * 7)
return d.toISOString().split('T')[0] return localDateStr(d)
} }
// ── Chart colours ────────────────────────────────────────────────────────── // ── Chart colours ──────────────────────────────────────────────────────────