Skip to content

Premium Analytics: type DateRange as a zoned instant - #52065

Open
chihsuan wants to merge 7 commits into
trunkfrom
change/wooa7s-2100-daterange-zoned
Open

Premium Analytics: type DateRange as a zoned instant#52065
chihsuan wants to merge 7 commits into
trunkfrom
change/wooa7s-2100-daterange-zoned

Conversation

@chihsuan

@chihsuan chihsuan commented Sep 8, 2026

Copy link
Copy Markdown
Member

Fixes WOOA7S-2100

Proposed changes

Keep Premium Analytics date ranges in the site's timezone so day boundaries and range lengths don't depend on the browser's timezone.

  • Use timezone-aware dates (TZDate) throughout date parsing, calculations, and the date picker.
  • Return no span for reversed ranges instead of a misleading one-hour span.
  • Update tests and docs to reflect the timezone requirement.

Related product discussion/links

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

No. The values written to the URL and to Stats requests are serialized from the epoch, so they are byte-identical.

Testing instructions

This is a typing change with no user-visible effect, so the useful test is that the date controls still behave.

  • Open the Premium Analytics dashboard on a site whose timezone is several hours from your browser's (Asia/Taipei against a US browser shows it best).
  • Open the date picker, choose a custom range, Apply. The pills and the chart should name the days you clicked, and the URL's from/to should carry the site's offset.
  • Step the window back and forward with the arrows. It should return to where it started, and the period label should keep reading "30 days" rather than 31.
  • Switch between presets and check the comparison dropdown still offers the right options and labels.

@github-actions

github-actions Bot commented Sep 8, 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 change/wooa7s-2100-daterange-zoned branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack change/wooa7s-2100-daterange-zoned
bin/jetpack-downloader test jetpack-mu-wpcom-plugin change/wooa7s-2100-daterange-zoned

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

github-actions Bot commented Sep 8, 2026

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

jp-launch-control Bot commented Sep 8, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/premium-analytics/packages/datetime/src/date-range-span.ts 27/27 (100.00%) 0.00% 0 💚
projects/packages/premium-analytics/packages/datetime/src/presets/primary.ts 79/79 (100.00%) 0.00% 0 💚
projects/packages/premium-analytics/packages/datetime/src/to-date-range.ts 7/7 (100.00%) 0.00% 0 💚
projects/packages/premium-analytics/packages/ui/src/date-range-popover/date-range-filter.tsx 22/22 (100.00%) 0.00% 0 💚

Full summary · PHP report · JS report

@chihsuan chihsuan changed the title Premium Analytics: type DateRange as a zoned instant (WOOA7S-2100) Premium Analytics: type DateRange as a zoned instant Sep 8, 2026
canStepForward and clampRangeEndToToday still took a plain Date for now
while drillDateRange required a TZDate, so the same package asked for the
site's clock in one signature and accepted the browser's in two others.
Narrow both, plus END_OF_BUCKET alongside the ADD_BY_UNIT it parallels, and
zone the call sites the narrowing catches.

Re-export TZDate from datetime so a consumer naming a DateRange bound does
not take its own direct dependency on @date-fns/tz, and point the three
production importers at that boundary. Drop PickerRange, which had become a
docblock-less twin of DateRange.

Sync the docs the retyping left behind: the startOfDayTZ and endOfDayTZ
@return lines, the formatters README parameter tables, and the README
sentence that asked callers to pass the site's now by hand.
getDateRangeSpan floors every measurement at 1, so a backwards range fell
through differenceInHours to a plausible-looking one-hour window rather
than to null, and stepDateRange and canStepForward then acted on it. The
range params are decoded from the URL independently with no ordering
check, so a hand-edited address reaches this.

Pre-existing rather than introduced here: the arithmetic is unchanged by
the retyping this branch does. Split out if it is better reviewed alone.
@chihsuan
chihsuan marked this pull request as ready for review September 8, 2026 09:59
@chihsuan
chihsuan requested a review from a team as a code owner September 8, 2026 09:59
@chihsuan chihsuan added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Sep 8, 2026

@louwie17 louwie17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great, the main hold back is the unneeded unit test, and also left a suggestion around adding a comment.

@chihsuan
chihsuan requested a review from louwie17 September 9, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants