fix some issues - including add ledger page and fix reoccuring completions

This commit is contained in:
JCEEE
2026-08-05 09:03:08 +01:00
parent 6e817be13f
commit d162ea762e
14 changed files with 993 additions and 546 deletions
+47 -4
View File
@@ -53,13 +53,17 @@ 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 back = (((wd - payday) % 7) + 7) % 7;
return addDaysStr(today, -back);
}
// The first configured-payday day strictly after dateStr (used to gate
// payday-settled bonus rewards). Weekly: periodEnd (weekStart+6) → next payday.
export function nextPaydayAfter(dateStr: string, payday: number, tz: string): string {
export function nextPaydayAfter(
dateStr: string,
payday: number,
tz: string,
): string {
let d = addDaysStr(dateStr, 1);
while (weekdayInTz(new Date(d + "T12:00:00Z"), tz) !== payday) {
d = addDaysStr(d, 1);
@@ -82,7 +86,11 @@ function monthEndStr(month?: string): string {
return `${month}-${String(lastDay).padStart(2, "0")}`;
}
export function periodStart(period: string, payday: number, tz: string): string {
export function periodStart(
period: string,
payday: number,
tz: string,
): string {
if (period === "daily") return todayInTz(tz);
if (period === "weekly") return weekStart(payday, tz);
if (period === "monthly") return monthStartStr();
@@ -96,7 +104,42 @@ export function periodEnd(period: string, start: string): string {
return start;
}
export function wallClockToUtc(dateStr: string, time: string, tz: string): number {
// The completion window a chore of a given frequency is "done for" in the
// current period. Weekly chores are done once per week ([weekStart, +7)),
// daily chores once per day ([today, +1)). Half-open [from, to).
export function periodWindow(
frequency: string,
payday: number,
tz: string,
): { from: string; to: string } {
if (frequency === "weekly") {
const from = weekStart(payday, tz);
return { from, to: addDaysStr(from, 7) };
}
const from = todayInTz(tz);
return { from, to: addDaysStr(from, 1) };
}
// True if any completion date falls within the current period window for the
// chore's frequency. Dates may be YYYY-MM-DD or ISO (time portion ignored).
export function isCompleteForPeriod(
frequency: string,
payday: number,
tz: string,
dates: string[],
): boolean {
const { from, to } = periodWindow(frequency, payday, tz);
return dates.some((d) => {
const day = (d || "").slice(0, 10);
return day >= from && day < to;
});
}
export function wallClockToUtc(
dateStr: string,
time: string,
tz: string,
): number {
const [y, m, d] = dateStr.split("-").map(Number);
const [h, min] = time.split(":").map(Number);
let epoch = Date.UTC(y, m - 1, d, h, min);