Skip to content

NWP-102: bucket daily volume by UTC day and sum integer minor units - #235

Open
qishenxu wants to merge 2 commits into
JJFromTenex:mainfrom
qishenxu:NWP-102-utc-daily-volume
Open

qishenxu wants to merge 2 commits into
JJFromTenex:mainfrom
qishenxu:NWP-102-utc-daily-volume

Conversation

@qishenxu

@qishenxu qishenxu commented Nov 3, 2026

Copy link
Copy Markdown

Ticket

Closes NWP-102 (partially — see "Notes for the reviewer")

What changed

The overview's daily volume now puts every payment on its UTC day and totals amounts exactly in integer minor units. Before, dailyVolume keyed each payment by the server's local date (toLocaleDateString("en-CA")) while its buckets were UTC days, so payments near midnight moved to the wrong day, or dropped out of the window, depending on the machine's timezone. It also accumulated floats in major units (amount / 100) and rounded at the end, which drifts by cents as transaction count grows. The fix uses the existing utcDayKey (src/lib/dates.ts) and sumMinorUnits (src/lib/money.ts). No new helpers, no seed changes. dailyVolume gained optional payments and now parameters (defaulting to the store and GENERATED_AT) so it can be tested; the overview call site is unchanged.

Spec: docs/specs/NWP-102-utc-daily-volume.md

How I verified it

  • npm test passes — Test Files 4 passed (4), Tests 30 passed (30)
  • New behavior is covered by a test — src/data/metrics.test.ts, run with TZ=America/Los_Angeles:
    • payments at 23:30 UTC and 00:15 UTC land on their own UTC days (the test first asserts the TZ really took effect, so it cannot pass vacuously)
    • 10,001 payments of 7 minor units sum exactly, and results are integers
    • both tests were run against the unfixed code first and failed
  • Checked it in the browser — not done; the change is covered by unit tests only

Acceptance criteria

The ticket asks for a diagnosis of three reports rather than listing checkboxes. Against those:

  • Berlin merchant: a whole day attributed to the wrong date — root cause: local-timezone bucketing in src/data/metrics.ts dailyVolume. Fixed.
  • Off by a few cents, growing with transaction count — root cause: float accumulation in major units in the same function. Fixed.
  • Refund-heavy merchant sees totals too high — not fixed. Likely cause: refunded payments are counted at the full payment.amount, but src/data/generate.ts:112 creates partial refunds dated by the refund. Separate change.
  • Payouts screen vs payments screen — not checked.

Bugs fixed along the way

None beyond the two above, which are both in dailyVolume.

Notes for the reviewer

Found while reading, deliberately left out of this PR (also listed in the spec):

  • src/data/metrics.ts sums USD, EUR and GBP together while its header says USD. That breaks the money rule and may contribute to the Berlin (EUR) report.
  • headlineMetrics gross volume adds refunded to captured. Needs a decision on what "gross volume" means.
  • Open question: whether the Berlin merchant expects statements in Europe/Berlin days. If so, that is a display-side change; bucketing stays UTC.

🤖 Generated with Claude Code

Jason Xu and others added 2 commits November 3, 2026 11:10
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dailyVolume keyed payments by the server's local date while its buckets
were UTC days, so payments near midnight moved or vanished depending on
TZ. It also accumulated floats in major units. Use utcDayKey and
sumMinorUnits, and add regression tests run under America/Los_Angeles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant