Repository navigation
Comment Date: Fix the human-diff date being off by the timezone offset - #86398
Draft
westonruter wants to merge 4 commits into
Draft
westonruter wants to merge 4 commits into
westonruter wants to merge 4 commits into
Conversation
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
🤖 PR meta 🤖⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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
|
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
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.
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 tomysql2date(). 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"). Sincehuman_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 theget_comment_timefilter instead ofget_comment_date.Testing Instructions
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:
Testing Instructions for Keyboard
Not applicable, since the change is to the server-rendered output only.
Screenshots or screencast
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.