Make WordPress Core

#63834 closed defect (bug) (reported-upstream)

Block post-date doesn't show date for postings modified on same day am/pm (Fix included)

Reported by: gchriz Owned by:
Priority: normal Milestone:
Component: Editor Version:
Severity: normal Keywords: has-patch close
Cc: Focuses:

Description

The block "post-date" used with displayType "modified" doesn't show anything if the creation of the post/page is before 01:00 pm and the last modification is on the same day.

That is due to a bug in the code.

In line 52 of file wp-includes/blocks/post-date.php the queried date format uses "h" for a 12-hour clock and therefore the comparison fails like described above.

if ( get_the_modified_date( 'Ymdhi', $post_ID ) > get_the_date( 'Ymdhi', $post_ID ) ) {

It needs to be "H" for 24-hour clock:

if ( get_the_modified_date( 'YmdHi', $post_ID ) > get_the_date( 'YmdHi', $post_ID ) ) {

Change History (6)

#1 @sabernhardt
15 months ago

  • Component General → Editor
  • Keywords block time modified removed
  • Version 6.8.2

Hi and thanks for the report!

This situation will need to be tested with the Gutenberg plugin, which already updated that comparison. ​GB70982 switched the 'Ymdhi' format to 'U' in the past few weeks. The modified date seems to work now with Gutenberg 21.4.0 activated.

The Ymdhi format goes back to GB46839 (synched in #58623 for WordPress 6.3).

#2 @gchriz
15 months ago

I realized that my report wasn't exact enough, IMHO.

So - for the records - here the improved sentence of my description:

The block "post-date" used with displayType "modified" doesn't show anything if the creation of the post/page is before 01:00 pm and the last modification is after 01:00 pm on the same day but less than 12 hours later than the creation time.

#3 @iamadisingh
15 months ago

This issue still exists in WordPress core. We should use Unix timestamp format 'U' for reliable numeric comparison:

<?php
if ( get_the_modified_date( 'U', $post_ID ) > get_the_date( 'U', $post_ID ) ) {

This matches the fix already implemented in Gutenberg PR [GB70982] and should be synced to WordPress core.

This ticket was mentioned in ​PR #9502 on ​WordPress/wordpress-develop by ​@iamadisingh.


15 months ago
#4

  • Keywords has-patch added

Fixes issue where post-date block with displayType "modified" fails to show modified dates when posts are created before 1:00 PM and modified after 1:00 PM on the same day.

Trac ticket: https://core.trac.wordpress.org/ticket/63834

#5 @westonruter
15 months ago

  • Keywords close added

If the issue is still present in core and it is also present in the Gutenberg plugin, the the issue should be reported on the Gutenberg repo and fixed with a PR to that repo. The fix will then be synced to core. This can then be closed as "reported upstream".

#6 @Mamaduka
11 months ago

  • Milestone Awaiting Review
  • Resolution → reported-upstream
  • Status new → closed

Closing as reported upstream. Link ​https://github.com/WordPress/gutenberg/issues/57915.

Note: See TracTickets for help on using tickets.