Skip to content

🎨 Showed site timezone, instead of device timezone, in post analytics#26229

Merged
troyciesco merged 2 commits intomainfrom
post-analytics-published-timezone
Feb 5, 2026
Merged

🎨 Showed site timezone, instead of device timezone, in post analytics#26229
troyciesco merged 2 commits intomainfrom
post-analytics-published-timezone

Conversation

@EvanHahn
Copy link
Contributor

@EvanHahn EvanHahn commented Feb 4, 2026

towards https://linear.app/ghost/issue/NY-951

Before (device in America/Chicago) After (site in Pacific/Honolulu)
Before After

Previously, post analytics showed the time in the device's timezone. Now, they show the time in the site's timezone.

Summary by CodeRabbit

Release Notes

  • New Features

    • Post analytics now display dates and times with timezone-aware formatting, ensuring accurate time representation across different regions.
  • Tests

    • Added comprehensive unit tests for timezone handling and date/time formatting utilities.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

This pull request introduces timezone-aware date and time formatting functionality. It adds a getSiteTimezone utility function to extract timezone from settings, implements a formatDisplayTime helper for timezone-aware time formatting using moment-timezone, and integrates these into the PostAnalyticsHeader component to display published date and time with proper timezone awareness.

Changes

Cohort / File(s) Summary
Timezone Extraction
apps/posts/src/utils/get-site-timezone.ts, apps/posts/test/unit/utils/get-site-timezone.test.ts
New utility function that retrieves timezone from settings array, validates it as a string, and falls back to 'Etc/UTC'. Includes comprehensive unit tests covering string validation, fallback behavior, and duplicate handling.
Time Formatting Utility
apps/shade/src/lib/utils.ts, apps/shade/test/unit/utils/utils.test.ts
New formatDisplayTime function that formats a date string in a specified timezone using moment-timezone (h:mma format). Includes tests validating formatting across multiple timezones and date boundary edge cases.
PostAnalyticsHeader Integration
apps/posts/src/views/PostAnalytics/components/post-analytics-header.tsx
Updated component to retrieve site timezone via getSiteTimezone, replaced direct moment-based formatting with new formatDisplayDate and formatDisplayTime helpers for timezone-aware date/time rendering.
Export and Configuration Updates
apps/shade/src/index.ts, apps/posts/test/.eslintrc.cjs
Added formatDisplayTime to public exports; added ESLint rule override to disable mocha arrow function restriction in test configuration.

Sequence Diagram

sequenceDiagram
    participant Header as PostAnalyticsHeader
    participant Global as Global Data
    participant TZ as getSiteTimezone
    participant Format as formatDisplayTime
    participant UI as Rendered Output

    Header->>Global: Retrieve settings
    Global-->>Header: settings array
    Header->>TZ: getSiteTimezone(settings)
    TZ-->>Header: timezone string
    Header->>Format: formatDisplayTime(published_at, timezone)
    Format-->>Header: formatted time string
    Header->>UI: Render with timezone-aware time
Loading

Poem

🐰 Hop, skip, and jump through zones we go,
Where timezones bloom and moments flow,
Settings whisper, formatters shine,
Africa to New York, all in time!
PostAnalytics now sees the light,
Every hour formatted just right! 🕐✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: displaying site timezone instead of device timezone in post analytics, which aligns with the core objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch post-analytics-published-timezone

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

towards https://linear.app/ghost/issue/NY-951

Previously, post analytics showed the time in the device's timezone.
Now, they show the time in the site's timezone.
@EvanHahn EvanHahn force-pushed the post-analytics-published-timezone branch from 8f0977d to dc937d7 Compare February 4, 2026 16:58
@EvanHahn EvanHahn marked this pull request as ready for review February 4, 2026 17:18
@EvanHahn EvanHahn requested a review from troyciesco February 4, 2026 17:18
* // 7:09pm
*/
export const formatDisplayTime = (dateString: string, timezone: string): string => (
moment(dateString).tz(timezone).format('h:mma')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this uses 12-hour time, not 24-hour time, like before. Happy to revert.

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I can tell it's a complete mix across the codebase.

Screenshot 2026-02-05 at 9 22 50 AM Screenshot 2026-02-05 at 9 21 19 AM

this seems consistent with what else is in shade, at least, so makes sense to me.

@EvanHahn EvanHahn added the ok to merge for me You can merge this on my behalf if you want. label Feb 4, 2026
Copy link
Contributor

@troyciesco troyciesco left a comment

Choose a reason for hiding this comment

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

lgtm - just noting i saw the year disappeared too in the new version, but that looks correct with how that function works (i.e. doesn't show currentYear)

@troyciesco troyciesco merged commit 7bf945b into main Feb 5, 2026
30 checks passed
@troyciesco troyciesco deleted the post-analytics-published-timezone branch February 5, 2026 14:46
betschki pushed a commit to magicpages/Ghost that referenced this pull request Feb 19, 2026
…TryGhost#26229)

towards https://linear.app/ghost/issue/NY-951

| Before (device in America/Chicago) | After (site in Pacific/Honolulu)
|
|---|---|
|
![Before](https://github.com/user-attachments/assets/fe470b04-9b6d-42ad-b004-9c920ad2b96d)
|
![After](https://github.com/user-attachments/assets/3101fcc4-a9b1-47b7-9ebe-00c768141d02)
|

Previously, post analytics showed the time in the device's timezone.
Now, they show the time in the site's timezone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok to merge for me You can merge this on my behalf if you want.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants