Fix period default dates shifting by one day in UTC+ timezones

toISOString() converts local midnight to UTC, producing the previous day
in any timezone east of UTC. Format dates using local getFullYear/Month/Date
instead.

https://claude.ai/code/session_014uUwDBtG5y5FuWcy5zqVD1
This commit is contained in:
Claude 2026-05-13 09:20:35 +00:00
parent 9d4533b7a1
commit 9eccc0af8b
No known key found for this signature in database

View file

@ -122,12 +122,11 @@ function fmtAmt(n) {
}
function defaultPeriod() {
const d = new Date();
const lastDay = new Date(d.getFullYear(), d.getMonth()+1, 0).getDate() === d.getDate();
const y = lastDay ? d.getFullYear() : (d.getMonth() === 0 ? d.getFullYear()-1 : d.getFullYear());
const m = lastDay ? d.getMonth() : (d.getMonth() === 0 ? 11 : d.getMonth()-1);
const from = new Date(y, m, 1);
const to = new Date(y, m+1, 0);
return { from: from.toISOString().slice(0,10), to: to.toISOString().slice(0,10) };
const isLastDay = d.getDate() === new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
const y = isLastDay ? d.getFullYear() : (d.getMonth() === 0 ? d.getFullYear() - 1 : d.getFullYear());
const m = isLastDay ? d.getMonth() : (d.getMonth() === 0 ? 11 : d.getMonth() - 1);
const fmt = dt => `${dt.getFullYear()}-${String(dt.getMonth()+1).padStart(2,'0')}-${String(dt.getDate()).padStart(2,'0')}`;
return { from: fmt(new Date(y, m, 1)), to: fmt(new Date(y, m + 1, 0)) };
}
// ========== CONFIG ==========