🐛 Fixed post analytics missing first-day traffic on later days#28233
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR refactors getRangeForStartDate to compute inclusive calendar-day ranges using moment-timezone instead of millisecond Date arithmetic. It resolves the runtime IANA timezone, computes publishedDate and today as startOf('day') moments in that timezone, and sets the range count from today.diff(publishedDate, 'days') + 1 (minimum 1). Tests were added with Vitest fake timers to verify inclusive counting relative to publish time-of-day and the formatted startDate. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/shade/test/unit/utils/utils.test.ts`:
- Around line 135-152: The tests for
getRangeForStartDate/getRangeDates/formatQueryDate are timezone-dependent and
can fail in non-US timezones; update the two specs to remove hard-coded
expectations by either (a) choosing start/publish instants that are unambiguous
in all timezones (e.g., use UTC-aligned times like '2026-05-26T12:00:00Z' and
set system time with vi.setSystemTime(new Date('2026-05-28T09:00:00Z'))), or (b)
compute the expected day/range dynamically using the test runtime zone
(Intl.DateTimeFormat().resolvedOptions().timeZone) and then assert against that
computed expected value; modify the tests referencing getRangeForStartDate,
getRangeDates, and formatQueryDate to implement one of these approaches so
assertions are robust across timezones.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ea199793-66c5-4a1f-81ca-34f10837cbcc
📒 Files selected for processing (2)
apps/shade/src/lib/app-utils.tsapps/shade/test/unit/utils/utils.test.ts
c7d27ac to
625c052
Compare
|
Actionable comments posted: 0 |
ref ONC-1771
Post analytics was calculating the publish-date range from elapsed hours, while the chart query dates are calendar-day based. This meant posts could lose their publication-day traffic whenever the current time was earlier than the original publish time.
So if you published on Monday at 11am, you'd have the following:
and so on
This PR updates the range calculation to count inclusive calendar days in the same timezone used by the chart date query, so the publish day is always included.
Before
After