Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(activity): correct Year trends per-day average for the current month - #79

Merged
saksham2001 merged 2 commits into
saksham2001:mainfrom
rgvxsthi:fix/audit-cleanup
Jul 12, 2026
Merged

saksham2001 merged 2 commits into
saksham2001:mainfrom
rgvxsthi:fix/audit-cleanup

Conversation

@rgvxsthi

Copy link
Copy Markdown
Contributor

Bug

In the Activity Year (12-month) trends, each month's total was divided by its full calendar length. For the in-progress current month this spread a partial-month total across 30/31 days — understating the current-month steps/day bar by up to ~3× (e.g. on the 10th: total/31 instead of total/10) and mildly dragging down the Year "avg/day" headline.

Only the current month was affected; completed months were correct. Bug is specific to the .twelveMonths builder — Day/Week/Month ranges were fine.

Fix

Divide the in-progress current month by elapsed calendar days (day-of-month); completed months keep their full calendar length. This matches the existing "total ÷ calendar days in period" convention (completed months already divide by full length regardless of data gaps).

let isCurrentMonth = cal.isDate(monthStart, equalTo: Date(), toGranularity: .month)
let days = isCurrentMonth
    ? cal.component(.day, from: Date())
    : (cal.range(of: .day, in: .month, for: monthStart)?.count ?? 30)

Validation

  • Completed months: else branch is byte-identical to before — no regression.
  • isCurrentMonth selects exactly the one current year+month bucket (same Calendar.current throughout — no tz/DST/rollover misfire).
  • Day 1 → ÷1; no div-by-zero.
  • Headline (dailyAverage) and distance/calories inherit the corrected value; no other consumers affected.

The 12-month (Year) trends builder divided every month's total by its full
calendar length. For the in-progress current month that spread a partial
total across 30/31 days, understating the current-month steps/day bar by up
to ~3x and dragging down the Year "avg/day" headline.

Divide the current month by elapsed calendar days (day-of-month) instead;
completed months keep their full calendar length, matching the existing
"total ÷ calendar days in period" convention. No other range affected.
@rgvxsthi
rgvxsthi requested a review from saksham2001 as a code owner July 10, 2026 12:34
@saksham2001
saksham2001 merged commit 952cf4f into saksham2001:main Jul 12, 2026
2 checks passed
@rgvxsthi
rgvxsthi deleted the fix/audit-cleanup branch July 12, 2026 09:14
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.

2 participants