Repository navigation
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @sanjeev00733! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
When a date is manually picked via the date picker, DateTimePicker emits a timezone-naive string (e.g. "2026-07-30T04:30:00"). The render function passed this to strtotime(), which assumes UTC because WordPress forces PHP's default timezone to UTC. wp_date() then applied the site's offset on top — shifting the displayed time by the full UTC offset a second time. Fix by replacing strtotime() with date_create_immutable() + wp_timezone(), which explicitly interprets the string as site-local time. If the string already carries a timezone indicator (as in the "Now" path), DateTimeImmutable ignores the $timezone argument — so this is safe for both code paths. Adds a regression test that sets the site timezone to Asia/Kolkata (UTC+5:30) and asserts the manually-set time renders correctly without double offset. Fixes WordPress#81084
f968c17 to
6c2cd67
Compare
mikachan
left a comment
There was a problem hiding this comment.
Thanks @sanjeev00733, and welcome! 👋
I think the fix is right. A timezone-naive datetime from the picker should be read in the site's timezone. The REST API treats a post's date field the same way. I checked that strings which already carry an offset still produce the same timestamp as before.
I've left a few inline comments. The main one is that the first test assertion would also pass without the fix.
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
- Assert on the rendered text (>04:30</time>) so the test catches the regression. The previous '04:30' substring also matched the datetime attribute, so it passed even without the fix. - Replace the four-line // comment above date_create_immutable() with a two-line /* */ block.
mikachan
left a comment
There was a problem hiding this comment.
Thanks for the updates! I think we can bring this in 🎉
What does this PR do?
Closes #81084
Fixes the
core/post-dateblock displaying the wrong time on the front end when a date is manually set via the date picker. On sites with a non-UTC timezone, the displayed time was shifted by the site's UTC offset — as if it were applied twice.Example (UTC+5:30):
30 July 2026, 4:30 AM30 July 2026, 10:00 AM❌30 July 2026, 4:30 AM✅Root cause
When a date is manually picked,
DateTimePickeremits a timezone-naive string such as"2026-07-30T04:30:00"with no UTC offset orZsuffix. The render function passed this directly tostrtotime():WordPress forces PHP's default timezone to UTC, so
strtotime()treats the string as UTC.wp_date()then converts that already-wrong UTC timestamp into the site's local timezone — applying the site offset a second time.Fix
Replace
strtotime()withdate_create_immutable()paired withwp_timezone(), which explicitly interprets the timezone-naive string as site-local time from the start:If the string already carries a timezone indicator (e.g. a
Zor+HH:MMsuffix, as produced by the "Now" path),DateTimeImmutableignores the$timezoneargument — so this is backward-compatible for both code paths.This is the same principle applied in #71430, which fixed the related bug in the fallback/legacy render path (
isset() === false). This PR fixes the remaining broken path: when a customdatetimeis explicitly set (isset() === true).How has this been tested?
30 July 2026, 4:30 AM10:00 AM(offset applied twice)4:30 AM(correct)phpunit/blocks/render-block-core-post-date.phptest-date-bug.mov
Types of changes
Checklist