Fix week date range off-by-one in BST timezone

toISOString() returns UTC — in BST (UTC+1) dates computed from new Date()
land one day early. Replace with local date components via fmt()/localStr().
Affects Weekly, Monthly, Rolling12Weeks, Rolling12Months.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-23 09:48:46 +00:00
parent 3e1851fa6d
commit 793e97dbbb
4 changed files with 17 additions and 7 deletions

View file

@ -6,7 +6,9 @@ import {
import { getActuals, getScheduled, getNetSales, getBudgets, downloadExport } from '../api'
import type { DeptActuals, WageBudget } from '../types'
function fmt(d: Date): string { return d.toISOString().slice(0, 10) }
function fmt(d: Date): string {
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
}
function addDays(d: Date, n: number): Date { const r = new Date(d); r.setDate(r.getDate() + n); return r }
function daysInMonth(y: number, m: number): number { return new Date(y, m, 0).getDate() }
function fmtMoney(n: number): string { return `£${Math.round(n).toLocaleString('en-GB')}` }
@ -15,7 +17,7 @@ function pctClass(pct: number): string { return pct <= 100 ? 'pct-green' : pct <
const DEPT_COLORS = ['#065f46','#059669','#0891b2','#7c3aed','#c2410c','#b45309','#0f766e','#4338ca','#be185d','#15803d']
export default function Monthly() {
const todayStr = new Date().toISOString().slice(0, 10)
const todayStr = fmt(new Date())
const todayYear = parseInt(todayStr.slice(0, 4))
const todayMonth = parseInt(todayStr.slice(5, 7))