some more improvements

This commit is contained in:
JCEEE
2026-09-15 15:14:18 +01:00
parent 833a34049e
commit 78f456bf77
8 changed files with 94 additions and 41 deletions
+5 -1
View File
@@ -53,7 +53,11 @@ export function addDaysStr(dateStr: string, days: number): string {
export function weekStart(payday: number, tz: string): string {
const today = todayInTz(tz);
const wd = weekdayInTz(new Date(), tz);
const back = (((wd - payday) % 7) + 7) % 7;
const sincePayday = (((wd - payday) % 7) + 7) % 7;
// The week CLOSES on payday, so it opens the day after: a payday itself
// belongs to the week ending that day (sincePayday 0 → back 6), e.g.
// payday Sunday → weeks run Monday..Sunday.
const back = sincePayday === 0 ? 6 : sincePayday - 1;
return addDaysStr(today, -back);
}