mirror of
https://github.com/kbenestad/reimburse.git
synced 2026-06-18 08:04:31 +00:00
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:
parent
9d4533b7a1
commit
9eccc0af8b
1 changed files with 5 additions and 6 deletions
11
index.html
11
index.html
|
|
@ -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 ==========
|
||||
|
|
|
|||
Loading…
Reference in a new issue