Skip to content

fix(stats): group Last 10 Days by the local date, not UTC - #632

Merged
LargeModGames merged 1 commit into
LargeModGames:mainfrom
kapok-4o:fix/stats-local-date
Sep 27, 2026
Merged

LargeModGames merged 1 commit into
LargeModGames:mainfrom
kapok-4o:fix/stats-local-date

Conversation

@kapok-4o

@kapok-4o kapok-4o commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #602. aggregate_days now delegates to aggregate_days_in(listens, tz), which keys a BTreeMap<NaiveDate, u64> by ended_at.with_timezone(tz).date_naive(), the same way qualified_day_totals does. aggregate_days keeps its signature and passes &Local, so neither caller changes.

Tests go through aggregate_days_in with fixed offsets, so they give the same result on a UTC runner and on any machine:

  • days_use_the_local_date_west_of_utc
  • days_use_the_local_date_east_of_utc
  • days_merge_plays_that_share_a_local_date

The Month/Year arms of filter_listens_for_period are left alone, as the issue says.

Testing

  • cargo fmt --all -- --check: clean
  • cargo clippy --no-default-features --features telemetry,tui -- -D warnings: clean
  • cargo test --no-default-features --features telemetry,tui: 1284 passed, 0 failed
  • cargo test --no-default-features --features telemetry,tui local_date: 3 passed, 1281 filtered out
  • With the date keyed by UTC again, all three new tests fail.

Additional notes

This is one of five small PRs I opened together (#602, #603, #594, #595, #599). Each changelog entry sits at a different spot in [Unreleased] so they merge without conflicts in any order.

Written with AI coding assistants: the fix was drafted by Codex, then extracted onto its own branch, checked against the issue and re-tested by Claude Code.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • The Stats panel and HTML listening recap now group listening activity by your local calendar date, improving date accuracy for plays near midnight.

aggregate_days labelled each play with its UTC date while the streak
strip and the hour chart use local time, so plays near midnight landed
on the wrong day outside UTC. Split out aggregate_days_in over a
TimeZone, keep aggregate_days as the Local wrapper, and test it with
fixed offsets so the result does not depend on the machine's zone.

Fixes LargeModGames#602

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: a0ba95a0-4ab8-4920-820a-08e2cc63c9ab

📥 Commits

Reviewing files that changed from the base of the PR and between 7c21df0 and 0518775.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/infra/history.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Daily listening totals now use local calendar dates instead of UTC dates. Fixed-offset tests verify date shifts and aggregation for records that share a local date.

Changes

Local-Date Listening Aggregation

Layer / File(s) Summary
Timezone-aware daily grouping
src/infra/history.rs, CHANGELOG.md
aggregate_days uses local dates for grouping and formats the date keys as YYYY-MM-DD. Tests cover east- and west-of-UTC offsets and combining plays on one local date. The changelog describes the change to the Stats panel and HTML recap.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 05187

The local-date grouping change appears ready to merge after normal checks.

Architecture Summary

Architecture risk: 🟡 Medium · up to 05187

The change affects 2 systems.

Changed systems: src, CHANGELOG.md

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.
  • observed — CHANGELOG.md (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in CHANGELOG.md: Adds a changelog entry stating that Stats and HTML recap play dates now use local dates rather than UTC dates.
  • observed — Modified behavior in src/infra/history.rs: aggregate_days now delegates to a helper using the local timezone. The helper groups records by their timezone-converted NaiveDate instead of UTC-formatted date strings.
  • observed — Modified behavior in src/infra/history.rs: Date keys are formatted as YYYY-MM-DD for display; previously the string label was used directly.
  • observed — Modified behavior in src/infra/history.rs: The tests import FixedOffset alongside TimeZone to construct explicit timezone cases.

Reliability and maintainability

  • inferred — Risk-relevant change factors for src: blast_radius_2; direct_dependents_2
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses the required conventional-commit prefix, includes an appropriate scope, and clearly describes the main change to group statistics by local date instead of UTC.
Linked Issues check ✅ Passed Issue [#602] requires local-date grouping, the existing aggregate_days signature, deterministic fixed-offset tests, and no changes to the Month and Year branches. The PR summary states that `agg…
Out of Scope Changes check ✅ Passed The changes stay within issue [#602]. The src/infra/history.rs changes implement local-date aggregation and add the required tests. The CHANGELOG.md entry documents that fix. No unrelated implemen…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
✨ Simplify code
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LargeModGames
LargeModGames merged commit 7ac352e into LargeModGames:main Sep 27, 2026
31 checks passed
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.

Stats "Last 10 Days" groups plays by UTC date, not local date

2 participants