Skip to content

Comment Date: Fix the human-diff date being off by the timezone offset - #86398

Draft
westonruter wants to merge 4 commits into
trunkfrom
fix/comment-date-human-diff-timezone
Draft

westonruter wants to merge 4 commits into
trunkfrom
fix/comment-date-human-diff-timezone

Conversation

@westonruter

Copy link
Copy Markdown
Member

What?

See #86095, where this was found in review.

Fixes the Comment Date block's "human-diff" format being off by the site's timezone offset.

Why?

On any site not set to UTC, a comment's relative date is wrong by the timezone offset. A comment posted ten minutes ago is shown as posted "2 hours ago" at UTC+2, "5 hours ago" at UTC-5, and "14 hours ago" at UTC+14.

How?

The timestamp was read with get_comment_date( 'U' ), which passes the comment's local date to mysql2date(). For the 'U' format, mysql2date() returns the timestamp plus the timezone offset rather than a Unix timestamp, as its inline comment notes ("Ideally should never be used"). Since human_time_diff() compares it with the current time in UTC, the offset ends up in the difference.

The timestamp is now read from the comment's GMT time with get_comment_time( 'U', true, false, $comment ), which yields the actual Unix timestamp. As a result, the value goes through the get_comment_time filter instead of get_comment_date.

Testing Instructions

  1. In Settings > General, set the timezone to one other than UTC, such as UTC+2.
  2. Post a comment on a post.
  3. In the Site Editor, set the Comment Date block in the single post template to the "human-diff" format (the relative "time ago" option).
  4. View the post. Before this change, the comment's date reads "2 hours ago"; with it, it reads "1 min ago".

A PHPUnit test is added that renders the block for a comment posted ten minutes ago at UTC, UTC+2, UTC-5, and UTC+14:

npm run test:unit:php -- -- --filter=Tests_Blocks_Render_Comment_Date

Testing Instructions for Keyboard

Not applicable, since the change is to the server-rendered output only.

Screenshots or screencast

Before After

Use of AI Tools

This PR was written with Claude Code using Claude Opus 5.5 (medium effort), which found the bug in a code review, wrote the fix and the test, and drafted this description.

westonruter and others added 2 commits November 5, 2026 14:43
The 'U' format of `get_comment_date()` comes from `mysql2date()`, which returns the timestamp plus the site's timezone offset rather than a Unix timestamp. Since `human_time_diff()` compares it with the current UTC time, a comment posted ten minutes ago on a site at UTC+2 was shown as posted two hours ago. The timestamp is now read from the comment's GMT time, which yields the actual Unix timestamp.

A test covers sites at, ahead of, and behind UTC.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: bb6ac735-361d-4cf9-8285-f96ee1a308af
Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: bb6ac735-361d-4cf9-8285-f96ee1a308af
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric a6f5151 trunk % Change
timeToFirstByte 43.5 ms +3.56% -3.68% 42.7 ms +8.31% -1.64% 1.87%
largestContentfulPaint 72 ms +8.33% -5.56% 72 ms +5.56% -5.56% 0%
lcpMinusTtfb 28.05 ms +3.21% -3.21% 28.1 ms +8.01% -3.91% -0.18%
wpBeforeTemplate 21.9 ms +1.96% -3.06% 21.53 ms +9.29% -1.21% 1.72%
wpTemplate 17.92 ms +3.68% -2.29% 17.38 ms +3.05% -5.87% 3.11%
wpTotal 40.17 ms +3.24% -3.73% 39.35 ms +8.34% -2.16% 2.08%
wpMemoryUsage 7.72 MB +0% -0% 7.69 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric a6f5151 trunk % Change
timeToFirstByte 35.85 ms +2.09% -2.93% 35.45 ms +3.24% -2.26% 1.13%
largestContentfulPaint 80 ms +0% -0% 80 ms +0% -5% 0%
lcpMinusTtfb 43.9 ms +2.96% -1.48% 42.25 ms +5.33% -2.49% 3.91%
wpBeforeTemplate 18.9 ms +4.92% -3.02% 18.77 ms +1.44% -0.75% 0.69%
wpTemplate 13.68 ms +5.04% -3.58% 13.74 ms +2.69% -3.64% -0.44%
wpTotal 33.06 ms +2.27% -3.6% 32.66 ms +2.91% -2.33% 1.22%
wpMemoryUsage 6.41 MB +0% -0% 6.38 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric a6f5151 trunk % Change
mediaProcessingJpeg 337.45 ms +5.41% -0.78% 335 ms +0.49% -0.17% 0.73%
mediaProcessingAvif 4933.23 ms +0.89% -0.28% 4929.51 ms +0.41% -0.21% 0.08%
mediaProcessingJpegToAvif 3359.35 ms +0.86% -0.03% 3353.74 ms +0.31% -0.17% 0.17%

media-upload

Metric a6f5151 trunk % Change
jpegUploadProcessing 1428.86 ms +1.47% -1% 1418.47 ms +0.44% -0.75% 0.73%
pngUploadProcessing 207.01 ms +8.3% -4.64% 217.42 ms +3.86% -3.17% -4.79%
largeJpegUploadProcessing 1413.33 ms +0.72% -0.15% 1415.42 ms +0.2% -0.15% -0.15%
multipleImageUploadProcessing 1485.49 ms +0.96% -0.66% 1490.18 ms +0.35% -0.83% -0.31%

post-editor

Metric a6f5151 trunk % Change
serverResponse 475.4 ms +3.86% -6.89% 477.61 ms +3.8% -8.29% -0.46%
firstPaint 372.14 ms +40.71% -15.16% 351.02 ms +11.54% -7.28% 6.02%
domContentLoaded 885.57 ms +0.81% -3.57% 832.05 ms +2.36% -0.28% 6.43%
loaded 886.8 ms +0.77% -3.56% 833.11 ms +2.34% -0.28% 6.44%
firstContentfulPaint 518.49 ms +5% -3.3% 485.69 ms +5.37% -1.62% 6.75%
firstBlock 2229.13 ms +5.53% -1.48% 2122.72 ms +0.35% -0.3% 5.01%
type 18.17 ms +6.22% -11.45% 16.18 ms +1.3% -7.23% 12.3%
typeWithoutInspector 16.79 ms +12.75% -9.77% 16.38 ms +5.19% -6.53% 2.5%
typeWithTopToolbar 22.02 ms +6.49% -6.4% 21.09 ms +4.03% -2.32% 4.41%
typeContainer 7.87 ms +13.34% -4.7% 8.4 ms +8.21% -5% -6.31%
focus 115.5 ms +4.17% -4.74% 120.16 ms +4.3% -3.49% -3.88%
firstFocus 253.15 ms +0% -0% 263.56 ms +0% -0% -3.95%
selectAll 418.24 ms +3.15% -3.34% 403.85 ms +2.05% -4.15% 3.56%
undo 30.48 ms +5.12% -6.89% 28.41 ms +7.15% -4.36% 7.29%
listViewOpen 80.63 ms +13.11% -8.77% 78.34 ms +7.3% -12.16% 2.92%
inserterOpen 42.98 ms +6.03% -8.21% 41.96 ms +12.35% -11.44% 2.43%
inserterHover 10.78 ms +5.29% -10.11% 10.78 ms +11.69% -7.88% 0%
inserterSearch 8.61 ms +4.53% -5.34% 8.11 ms +2.71% -3.45% 6.17%
loadPatterns 621.01 ms +2.06% -3.19% 626.22 ms +4.55% -2.96% -0.83%
wpTotal 465.87 ms +3.89% -7.04% 467.99 ms +3.82% -8.45% -0.45%
wpMemoryUsage 14.78 MB +0% -0% 14.74 MB +0% -0% 0.24%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric a6f5151 trunk % Change
serverResponse 383.5 ms +1.51% -7.29% 380.93 ms +1.62% -6.53% 0.67%
firstPaint 332.86 ms +6.56% -4.16% 300.28 ms +12.47% -8.96% 10.85%
domContentLoaded 829.84 ms +2.36% -1.07% 818.39 ms +2.64% -0.58% 1.4%
loaded 830.89 ms +2.36% -1.08% 819.36 ms +2.63% -0.57% 1.41%
firstContentfulPaint 476.36 ms +4.03% -2.04% 468.92 ms +1.89% -2.18% 1.59%
firstBlock 2292.58 ms +8.19% -0.72% 2282.78 ms +0.33% -0.97% 0.43%
type 16.91 ms +8.4% -9.7% 17.02 ms +6.76% -6.76% -0.65%
navigate 109.76 ms +2.28% -1.07% 101.25 ms +10.53% -3.75% 8.4%
loadPatterns 1191.81 ms +8.78% -2.34% 1195.45 ms +3.15% -14.36% -0.3%
loadPages 950.83 ms +2.02% -3.16% 951.07 ms +2.62% -1.54% -0.03%
wpTotal 374.27 ms +1.38% -7.52% 371.72 ms +1.67% -6.72% 0.69%
wpMemoryUsage 12.79 MB +0% -0% 12.76 MB +0% -0% 0.27%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

8c2848c Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Navigates the items list via UP/DOWN arrow keys in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByLabel('Page Two')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByLabel('Page Two') with timeout 5000ms
  - waiting for getByLabel('Page Two')
    14 × locator resolved to <button type="button" tabindex="-1" aria-pressed="false" id="view-list-0-177-item-wrapper" class="dataviews-view-list__item" aria-labelledby="view-list-0-177-label" aria-describedby="view-list-0-177-description"></button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:146:49
Page List converts to Navigation Links with entity bindings in /test/e2e/specs/editor/blocks/navigation.spec.js, passed after 1 failed attempt.
Error: expect(locator).toContainText(expected) failed

Locator: getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ })
Expected substring: "test-page-1"
Received string:    "Link to:Cat/catPagePublished"
Timeout: 5000ms

Call log:
  - Expect "toContainText" getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ }) with timeout 5000ms
  - waiting for getByRole('region', { name: 'Editor settings' }).getByRole('tabpanel', { name: 'Content' }).getByRole('button', { name: /Link to:/ })
    14 × locator resolved to <button type="button" aria-expanded="false" aria-haspopup="dialog" class="components-button link-preview-button is-next-40px-default-size is-secondary">…</button>
       - unexpected value "Link to:Cat/catPagePublished"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation.spec.js:1949:31
Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 6,
+   "offset": 6,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
does not select blocks in the canvas preview when editing from the sidebar (Site Editor v2) in /test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator: getByRole('combobox', { name: 'Search or type URL' })
Expected: focused
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeFocused" getByRole('combobox', { name: 'Search or type URL' }) with timeout 5000ms
  - waiting for getByRole('combobox', { name: 'Search or type URL' })

    at LinkControl.useLinkControlSearch (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:416:47)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:179:21
should give the image its context menu while selected @WebKit @Firefox in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Test timeout of 100000ms exceeded.
should place the caret at the click position when clicking a block that is not selected in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

@@ -1,9 +1,9 @@
  Array [
    Object {
      "attributes": Object {
-       "content": "First!",
+       "content": "First",
      },
      "name": "core/paragraph",
    },
    Object {
      "attributes": Object {

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:952:41
should undo without broken temporary state in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:image -->
- <figure class="wp-block-image"><img alt=""/></figure>
+ <!-- wp:image {"id":20,"sizeSlug":"full","linkDestination":"none"} -->
+ <figure class="wp-block-image size-full"><img src="http://localhost:8891/wp-content/uploads/2026/11/7ea61468-ae41-40f7-8d63-71e16ca26700.png" alt="" class="wp-image-20"/></figure>
  <!-- /wp:image -->
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/image.spec.js:432:49

8c2848c Run

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Nov 5, 2026
@westonruter westonruter added [Block] Comment Date Affects the Comment Date Block [Type] Bug An existing feature does not function as intended labels Nov 5, 2026
westonruter and others added 2 commits November 6, 2026 13:45
Keep the GMT `get_comment_time()` call for the human-diff timestamp, along with the `false` guard that trunk added for the `get_comment_date()` call it replaces. Append the changelog entry after the ones trunk added.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: edbfb274-a32d-4560-899d-effa9b02ce79
Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: edbfb274-a32d-4560-899d-effa9b02ce79

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Comment Date Affects the Comment Date Block [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant