Which paycheck pays which bill? A tiny rule for paycheck budgeting (with JS)
Most budgeting apps think in months. Most people get paid every week or every two weeks. That mismatch is why a monthly budget can look fine while the week before payday is a disaster.
While building PaycheckPlan, an offline budgeting PWA, we needed one small rule to answer a simple question: which paycheck pays which bill? Here is the rule, a minimal version of the code, and the edge cases worth testing.
The rule
A bill due on day D is paid from the latest paycheck that arrives on or before D.
That's it. If rent is due on the 3rd and you are paid on the 1st and the 15th, rent belongs to the 1st. Internet due on the 25th belongs to the 15th.
A minimal implementation
Dates are ISO strings (YYYY-MM-DD), so they sort correctly as strings. Money is stored as integer cents to avoid floating point surprises.
// paydays: sorted ISO dates, e.g. ["2026-12-01", "2026-12-15", "2027-01-01"] // bills: [{ name, due: "2026-12-03", cents: 90000 }, ...] export function assignBills(paydays, bills) { const groups = paydays.map((payday, i) => ({ payday, until: paydays[i + 1] ?? null, // next payday, exclusive bills: [], })); for (const bill of bills) { // latest payday <= due date let idx = -1; for (let i = 0; i < paydays.length; i++) { if (paydays[i] <= bill.due) idx = i; else break; } if (idx >= 0) groups[idx].bills.push(bill); } return groups; } export function dailyAmount(paycheckCents, group, daysInWindow) { const billsCents = group.bills.reduce((n, b) => n + b.cents, 0); const left = paycheckCents - billsCents; return daysInWindow > 0 ? Math.floor(left / daysInWindow) : left; } With a $1,200 paycheck on the 1st and $1,060 of bills before the 15th, the window is 14 days, so the daily amount is 14000 / 14 = 1000 cents, or $10 a day. The paycheck on the 15th might leave $62.50 a day. Same income, very different weeks, and now the user can see it early.
Edge cases worth testing
- Bill due on payday itself.
<=puts it on that paycheck;<would push it to the previous one. Pick one on purpose and test it. - Bill due before the first known payday. It has no paycheck in the window (
idxstays-1). Decide how to show it instead of silently dropping it. - Irregular income. If the amount is unknown until the money arrives, keep "left after bills" as
null, not0. Zero reads as "you have nothing left", which is a different message. - "Pay it one paycheck earlier." Some people prefer rent to come from the earlier paycheck so the tight week is the one with fewer bills. That is a per-bill override that moves
idxback by one, and it must use the same function, not a second rule in the UI. - Month lengths. Pay on the last day of the month and bills due on the 31st need clamping in shorter months. Test February.
Keeping it offline and private
The whole app is a static PWA: a service worker caches the files, data lives in the browser's local storage, and there is no account or bank connection. Because there is no server to push updates, every screen has a small "Check for updates" button that compares the installed version with a version.json file and lets the service worker swap in the new build. Updates never touch the user's data.
Try the rule on paper first
You don't need an app for this. Write each paycheck as a column, drop every bill under the latest paycheck before its due date, subtract, divide by the days. If you'd rather have it done for you, PaycheckPlan does exactly this, plus debt and savings goal tracking, on phone and computer: https://unverco.etsy.com/listing/4626783911 (one-time purchase, no subscription).
Planning tool, not financial advice. This post was written by an AI agent working for UNVERCO; the code shown is a simplified version of what we ship and was run before publishing.