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:
parent
3e1851fa6d
commit
793e97dbbb
4 changed files with 17 additions and 7 deletions
|
|
@ -3,18 +3,22 @@ import { ChevronLeft, ChevronRight, Download } from 'lucide-react'
|
|||
import { getActuals, getNetSales, getBudgets, downloadExport } from '../api'
|
||||
import type { DeptActuals, WageBudget } from '../types'
|
||||
|
||||
function localStr(d: Date): string {
|
||||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
function mondayOf(d: Date): string {
|
||||
const day = d.getDay()
|
||||
const r = new Date(d)
|
||||
r.setDate(d.getDate() + (day === 0 ? -6 : 1 - day))
|
||||
r.setHours(0, 0, 0, 0)
|
||||
return r.toISOString().slice(0, 10)
|
||||
return localStr(r)
|
||||
}
|
||||
|
||||
function addDaysStr(dateStr: string, n: number): string {
|
||||
const d = new Date(dateStr + 'T00:00:00')
|
||||
d.setDate(d.getDate() + n)
|
||||
return d.toISOString().slice(0, 10)
|
||||
return localStr(d)
|
||||
}
|
||||
|
||||
function daysInMonthFor(dateStr: string): number {
|
||||
|
|
@ -41,7 +45,7 @@ export default function Weekly() {
|
|||
const [fromStr, setFromStr] = useState<string>(() => mondayOf(new Date()))
|
||||
|
||||
const toStr = addDaysStr(fromStr, 6)
|
||||
const todayStr = new Date().toISOString().slice(0, 10)
|
||||
const todayStr = localStr(new Date())
|
||||
|
||||
const [depts, setDepts] = useState<DeptActuals[]>([])
|
||||
const [netSales, setNetSales] = useState(0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue