Skip to content

fix: send snippet modification dates with a UTC offset (3.10.1) - #468

Merged
ramiy merged 2 commits into
corefrom
fix/modified-timezone-release/core
Aug 27, 2026
Merged

fix: send snippet modification dates with a UTC offset (3.10.1)#468
ramiy merged 2 commits into
corefrom
fix/modified-timezone-release/core

Conversation

@TallblokeUK

Copy link
Copy Markdown
Contributor

Targeting core for 3.10.1. Same change as #463, which targets core-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() writes gmdate( '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't
  • the inline snippetsList payload in Manage_Menu_Assets

The 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-aware get_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.

before after
Modified cell 6 hours from now 21 minutes ago
datetime attribute 2026-08-27 07:35:20 2026-08-27T07:35:20+00:00

Plus 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:js and lint:styles clean.

Note

No changelog entry, consistent with #461 and #462 — didn't want to pick a version ahead of (Tag): Prepare.

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>
@TallblokeUK TallblokeUK added the run-tests Trigger automated tests label Aug 27, 2026
@ramiy

ramiy commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Cherry pick for #463

@ramiy
ramiy merged commit 4799f9c into core Aug 27, 2026
11 checks passed
@ramiy
ramiy deleted the fix/modified-timezone-release/core branch August 27, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-tests Trigger automated tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants