Skip to content

Premium Analytics: fix the sub-day previous-period comparison range - #51374

Open
retrofox wants to merge 2 commits into
trunkfrom
fix/sub-day-comparison-range
Open

Premium Analytics: fix the sub-day previous-period comparison range#51374
retrofox wants to merge 2 commits into
trunkfrom
fix/sub-day-comparison-range

Conversation

@retrofox

Copy link
Copy Markdown
Contributor

Proposed changes

The sub-day branch of getComparisonRangeFromPreset() mirrors a rolling window by shifting both ends by to - from. The ends are inclusive, so that span is one millisecond short of the window's real duration, and the shifted to lands exactly on the reference's from: the first instant of the primary window instead of the last instant before it.

At day granularity the stray millisecond never crosses a day boundary, so nothing was visible. At hourly granularity (#51166) it pulls the whole comparison series one bucket late: its last bucket is the primary's first, and the previous-period tooltip names the next hour. Root-cause context in this #51166 comment.

The fix shifts previous-period by the inclusive duration (windowMs + 1). The previous-month and previous-year branches already preserve the inclusive shape through their calendar shift, so they stay untouched.

The sub-day tests now use inclusive ends, the shape every preset actually produces (endOfHour, endOfDay); the old exact-instant reference was asserting the buggy boundary. A new case pins the last-24-hours shape, and another the adjacency invariant: the previous window ends immediately before the reference begins.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

pnpm --dir projects/packages/premium-analytics run test

get-comparison-range.test.ts pins the mirror. On trunk alone there is no visible change: at day granularity both boundaries resolve to the same calendar days. With #51166 checked out on top, pick Last 24 hours with comparison on and hover the Traffic chart: the previous-period row names the same hour as the tick under it, one day back.

@retrofox
retrofox requested a review from a team as a code owner August 18, 2026 23:54
@retrofox retrofox added the [Status] Needs Review This PR is ready for review. label Aug 18, 2026
@retrofox retrofox self-assigned this Aug 18, 2026
@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the fix/sub-day-comparison-range branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/sub-day-comparison-range
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/sub-day-comparison-range

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Cannot generate coverage summary while tests are failing. 🤐

Please fix the tests, or re-run the Code coverage job if it was something being flaky.

Full summary · PHP report · JS report

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @retrofox LGTM and tested well 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants