Skip to content

Premium Analytics: resolve full ISO Stats dates to the site timezone - #49878

Closed
kangzj wants to merge 1 commit into
trunkfrom
fix/wooa7s-1580-stats-iso-dates
Closed

Premium Analytics: resolve full ISO Stats dates to the site timezone#49878
kangzj wants to merge 1 commit into
trunkfrom
fix/wooa7s-1580-stats-iso-dates

Conversation

@kangzj

@kangzj kangzj commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Why this matters

The premium-analytics Stats data layer accepts full ISO from/to dates (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 like 2026-06-23T23:00:00-08:00 was reduced with a naive split('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-bearing from/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.
  • Added an optional timezone argument (defaults to getSiteTimezone()) so the conversion is unit-testable without mocking the core-data store.
  • Hardened 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.ts
  • Confirm the new cases pass:
    • An offset-bearing range that crosses midnight relative to the site timezone shifts to the correct calendar day (e.g. 2026-06-23T23:00:00-08:00 with site TZ +05:302026-06-24).
    • The end date is treated as an inclusive calendar day.
    • Date-only and timezone-naive inputs are unchanged.

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.
@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!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 24, 2026
@kangzj
kangzj marked this pull request as draft June 24, 2026 03:34
@kangzj kangzj closed this Aug 11, 2026
@github-actions github-actions Bot removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Aug 11, 2026
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.

1 participant