Skip to content

CMM-1095: Fix stats off-by-an-hour by reading the site's named timezone - #23124

Merged
adalpari merged 2 commits into
trunkfrom
cmm-1095-jetpack-app-jetpack-stats-are-off-by-an-hour
Jul 22, 2026
Merged

CMM-1095: Fix stats off-by-an-hour by reading the site's named timezone#23124
adalpari merged 2 commits into
trunkfrom
cmm-1095-jetpack-app-jetpack-stats-are-off-by-an-hour

Conversation

@adalpari

@adalpari adalpari commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description

Daily stats reset to zero an hour early (e.g. at 23:00 instead of 00:00) for
users whose site uses a DST timezone, such as Europe/Madrid.

The previous fix (#22480) intended to make the stats "day" boundary DST-safe by
storing the site's named (Olson) timezone in SiteModel.timezone and letting
SiteUtils.getNormalizedTimezone resolve DST from it. However, it read the wrong
JSON field: the WP.com API exposes the named timezone under different keys
depending on the endpoint:

  • Site info (/me/sites, /sites/$id) → options.timezone (e.g. "Europe/Madrid")
  • Site settings (/sites/$id/settings) → settings.timezone_string

Because the site-info response never contains timezone_string, the condition was
always false and SiteModel.timezone fell back to the numeric gmt_offset. A
numeric offset carries no DST rules and goes stale across DST transitions, so
"today" could be computed an hour ahead — at 23:00 Madrid (22:00 UTC → 00:00 in a
stale GMT+2) the app requested tomorrow's date and the server returned zeros.

This PR reads the correct options.timezone field. The DST-safe normalization
added in #22480 is unchanged and now actually receives a named zone.

Note: this affects the legacy stats screen (ui/stats/refresh/…), which derives
the request date from SiteModel.timezone. The newer ui/newstats/… screen uses
the device timezone and is out of scope here.

Testing instructions

Note

This fix only affects the old stats screen. To see the old stats screen you
must log in with a non-admin user (admins are routed to the new stats screen).

  1. Log in with a non-admin user on a WordPress.com/Jetpack site.
  2. Open Stats and confirm the old stats screen is shown.
  • Verify the stats (Traffic / Days, Today) load and show the correct data for
    the current day, matching the web Jetpack stats.

The site-info endpoint returns the Olson timezone under `options.timezone`,
not `timezone_string`, so the previous fix silently fell back to the stale
numeric `gmt_offset`, shifting the stats "day" boundary by an hour across DST.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dangermattic

dangermattic commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot

wpmobilebot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr23124-1275aa6
Build Number1498
Application IDcom.jetpack.android.prealpha
Commit1275aa6
Installation URL5f96ti89llqso
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr23124-1275aa6
Build Number1498
Application IDorg.wordpress.android.prealpha
Commit1275aa6
Installation URL1g5mrrkag0d3g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 37.74%. Comparing base (44f24ca) to head (05e1861).

Files with missing lines Patch % Lines
...id/fluxc/network/rest/wpcom/site/SiteRestClient.kt 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #23124      +/-   ##
==========================================
+ Coverage   37.71%   37.74%   +0.02%     
==========================================
  Files        2343     2343              
  Lines      127380   127380              
  Branches    17674    17674              
==========================================
+ Hits        48047    48078      +31     
+ Misses      75393    75358      -35     
- Partials     3940     3944       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adalpari
adalpari marked this pull request as ready for review July 21, 2026 14:44
@adalpari
adalpari requested a review from nbradbury July 21, 2026 14:44

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

Fix is good! :shipit:

@adalpari
adalpari enabled auto-merge (squash) July 22, 2026 08:01
@adalpari
adalpari merged commit 49a63f1 into trunk Jul 22, 2026
21 of 23 checks passed
@adalpari
adalpari deleted the cmm-1095-jetpack-app-jetpack-stats-are-off-by-an-hour branch July 22, 2026 08:16
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.

4 participants