Skip to content

Conversation

westonruter
Copy link
Member

Fixes #39984.

The date/time being displayed in the Date block is currently using gmdate():

$formatted_date = gmdate( empty( $attributes['format'] ) ? get_option( 'date_format' ) : $attributes['format'], $post_timestamp );

This is incorrect. For comparison, refer to core's get_post_time() function as used by get_the_date() as used in classic themes. It uses wp_date() as follows:

$time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null );

When the $timezone parameter is not passed to wp_date() then it uses the current timezone as specified in the blog's settings.

Testing

I added a Date block in a row in the Single template in Twenty Twenty-Five:

Screenshot 2025-08-31 at 22 29 06

I also have my timezone set to America/Los Angeles:

image

The current time for me right now is 22:35 (10:35pm) on August 31st. In the block editor, I see this reflected correctly when showing the template in the block editor:

image

However, if I view the post on the frontend, I see September 1st, since that is the current date in UTC/GMT:

image

When I switch to the code in this branch so that wp_date() is used instead, then I see the expected date of August 31st:

image

@westonruter westonruter added the [Type] Bug An existing feature does not function as intended label Sep 1, 2025
@westonruter westonruter added the [Block] Post Date Affects the Post Date Block label Sep 1, 2025
Copy link

github-actions bot commented Sep 1, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: ockham <bernhard-reiter@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: ryelle <ryelle@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

github-actions bot commented Sep 1, 2025

Flaky tests detected in 580f81f.
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.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17368683633
📝 Reported issues:

Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thank you for the fix!

@westonruter westonruter merged commit 95bc550 into trunk Sep 1, 2025
78 checks passed
@westonruter westonruter deleted the fix/date-block-timezone branch September 1, 2025 15:54
@github-actions github-actions bot added this to the Gutenberg 21.6 milestone Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Date Affects the Post Date Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Post Date block: Different display when site & user timezone don't match
2 participants