Function: overageApprovalWeekToPayWeek()
overageApprovalWeekToPayWeek(
weekStartIso):string
Defined in: src/lib/dates/index.ts:141
Map an overage approval's stored week_start to the pay engine's Monday-anchored overage week key by
snapping it FORWARD to the nearest Monday (a no-op when it is already a Monday). The single seam
between billing and pay:
- New approvals (ADR-0049) are stored on the unified Mon–Sun week, so this is the identity.
- Legacy approvals stored on the old Sun–Sat billing week map to the next-day Monday, exactly as
before — so existing approved overage keeps BOTH its billing match (on the stored Sunday
week_start, against an un-migrated legacy invoice) AND its pay match (on this Monday key).
No approval rows are rewritten by the unification; this function absorbs both anchors. Once the legacy Sunday tail has fully settled it degenerates to a pure identity and can be inlined.
Parameters
weekStartIso
string
The approval's stored week_start as YYYY-MM-DD (Sunday legacy or Monday new).
Returns
string
The Monday-anchored ISO pay-week start (weekStartIso snapped forward to its Monday).
Throws
DateError if weekStartIso is not a valid YYYY-MM-DD date (propagated from fromISO).
Example
overageApprovalWeekToPayWeek('2026-06-21'); // Sunday → '2026-06-22' (legacy)
overageApprovalWeekToPayWeek('2026-06-22'); // Monday → '2026-06-22' (new, identity)