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
+8 -1
View File
@@ -5,6 +5,7 @@ import {
periodEnd,
nextPaydayAfter,
weekStart,
weekdayInTz,
bonusWindow,
completionInWindow
} from '@shared/timezone';
@@ -47,7 +48,13 @@ function claimableStamp(cfg: any, payday: number, tz: string) {
const now = todayInTz(resolveServerTz(tz));
const start = cfg.period === 'monthly' ? `${now.slice(0, 7)}-01` : weekStart(payday, tz);
const end = periodEnd(cfg.period, start);
return { claimable: 'payday', settleDate: nextPaydayAfter(end, payday, tz) };
// Weeks close on payday, so a weekly window's end IS the settle date —
// nextPaydayAfter(end) would skip a whole extra week.
const settle =
weekdayInTz(new Date(end + 'T12:00:00Z'), tz) === payday
? end
: nextPaydayAfter(end, payday, tz);
return { claimable: 'payday', settleDate: settle };
}
function targetChoreFor(cfg: any, memberId: string): string | undefined {
+4 -1
View File
@@ -199,7 +199,10 @@ export async function releaseWeek(pb: any, famId: string) {
if (!fam) throw new Error('Fam not found');
const wsToday = weekStart(payday, tz);
const target = new Date(wallClockToUtc(wsToday, paydayTime || '18:00', tz));
// Settlement lands on payday itself — the SIXTH day of the wsToday week
// (weeks close on payday), not on weekStart.
const paydayDate = addDaysStr(wsToday, 6);
const target = new Date(wallClockToUtc(paydayDate, paydayTime || '18:00', tz));
if (Date.now() < target.getTime()) {
return {
settled: false,
+3 -2
View File
@@ -3,10 +3,11 @@ import { famMeta } from './fam';
// Week start (payday-anchored) for an arbitrary YYYY-MM-DD date — a
// parametric form of `weekStart()` so we can bucket historical weeks, not
// just the current one.
// just the current one. Weeks close on payday (open the day after).
function weekStartFor(dateStr: string, payday: number, tz: string): string {
const wd = weekdayInTz(new Date(dateStr + 'T12:00:00Z'), tz);
const back = (((wd - payday) % 7) + 7) % 7;
const sincePayday = (((wd - payday) % 7) + 7) % 7;
const back = sincePayday === 0 ? 6 : sincePayday - 1;
return addDaysStr(dateStr, -back);
}