fix: send snippet modification dates with a UTC offset (3.10.1) - #468
Merged
Conversation
The Modified column showed recently saved snippets in the future — six hours ahead on a UTC-6 site, and by whatever the offset happens to be elsewhere. `Snippet::update_modified()` writes `gmdate( 'Y-m-d H:i:s' )`, so the stored value is UTC but carries no offset. Both paths that hand snippets to the browser passed it through verbatim: the REST response, whose schema already declares `'format' => 'date-time'`, and the inline `snippetsList` payload on the manage screen. The table then calls `humanTimeDiff( snippet.modified )`, and an offset-less string is read as local time, putting every recent snippet ahead of now. `Snippet::get_modified_iso()` returns the same instant as ISO 8601 with an explicit offset, reusing the existing UTC-aware `get_modified_timestamp()`. Both output paths now send that, which also makes the `<time datetime="...">` attribute valid where it previously was not. The stored format is untouched, so nothing about how dates are written or compared changes. Verified against a reproduction of the reported environment — WordPress 7.0.4, PHP 8.2.33, 3.10.0, 190 snippets, site at UTC-6. The Modified cell went from "6 hours from now" to "21 minutes ago", with the datetime attribute changing from "2026-08-27 07:35:20" to "2026-08-27T07:35:20+00:00". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
|
Cherry pick for #463 |
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.
Targeting
corefor 3.10.1. Same change as #463, which targetscore-beta— whichever suits the release, the other can be closed.The bug
Reported from support against 3.10.0: the Modified column shows recently saved snippets in the future — "6 hours from now" on a site at UTC−6, and by whatever the offset is elsewhere. Reproduced exactly.
Cause
Snippet::update_modified()writesgmdate( 'Y-m-d H:i:s' ). The value is UTC, but that format carries no offset.Both paths that hand snippets to the browser passed it through verbatim:
Snippets_REST_Controller::prepare_item_for_response()— whose schema already declares'format' => 'date-time'and describes the field as "in ISO format", which it wasn'tsnippetsListpayload inManage_Menu_AssetsThe table then calls
humanTimeDiff( snippet.modified ). An offset-less string is parsed as local time, so on any site behind UTC every recent snippet lands in the future by exactly the site's offset.The fix
Snippet::get_modified_iso()returns the same instant as ISO 8601 with an explicit offset, reusing the existing UTC-awareget_modified_timestamp(). Both output paths now send that.Side benefit:
<time datetime="…">is now a valid datetime attribute, which it previously wasn't.The stored format is unchanged — nothing about how dates are written, sorted or compared moves. This only affects what goes over the wire.
Verification
Reproduced the reporter's environment: WordPress 7.0.4, PHP 8.2.33, Code Snippets 3.10.0 (the released zip), 190 snippets, site at UTC−6.
6 hours from now21 minutes agodatetimeattribute2026-08-27 07:35:202026-08-27T07:35:20+00:00Plus two unit tests covering the ISO output and the null case for a snippet that was never modified. They fail without the change.
PHPUnit: 159 tests, 0 failures.
lint:jsandlint:stylesclean.Note
No changelog entry, consistent with #461 and #462 — didn't want to pick a version ahead of
(Tag): Prepare.