Premium Analytics: resolve full ISO Stats dates to the site timezone - #49878
Closed
kangzj wants to merge 1 commit into
Closed
Premium Analytics: resolve full ISO Stats dates to the site timezone#49878kangzj wants to merge 1 commit into
kangzj wants to merge 1 commit into
Conversation
The Stats data layer reduced from/to to a date with a naive split('T')[0],
which keeps whatever offset the ISO string carries. The Stats backend
interprets date boundaries in the site timezone, so offset-bearing inputs
landed on the wrong calendar day at day boundaries. Convert such inputs into
the site timezone before reducing them to the date-only range; date-only and
timezone-naive inputs pass through unchanged.
Contributor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
kangzj
marked this pull request as draft
June 24, 2026 03:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this matters
The premium-analytics Stats data layer accepts full ISO
from/todates (so callers can drive Stats and Woo report hooks from the same date range), but the Stats backend interprets date boundaries in the site timezone. Before this change, an offset-bearing range like2026-06-23T23:00:00-08:00was reduced with a naivesplit('T')[0], keeping whatever offset the string carried — so at day boundaries the request landed on the wrong calendar day and returned data for the wrong day.Proposed changes
reportParamsToStatsQueryParams()now resolves offset-bearingfrom/to(Z/±hh:mm) into the site timezone before reducing them to the date-only range the Stats backend expects. Date-only and timezone-naive inputs pass through unchanged.timezoneargument (defaults togetSiteTimezone()) so the conversion is unit-testable without mocking the core-data store.getDaysBetweenInclusive()to tolerate full ISO inputs (drops any time component) so a future caller can't silently regress the day count.Related product discussion/links
Does this pull request change what data or activity we track or use?
No. It only corrects how an existing date range is normalized before it is sent to the Stats API.
Testing instructions
cd projects/packages/premium-analytics && pnpm test packages/data/src/utils/__tests__/stats-params.test.ts2026-06-23T23:00:00-08:00with site TZ+05:30→2026-06-24).