Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's always showing posted 1 seconds ago when post_date_gmt is '0000-00-00 00:00:00' #7014

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

rana01645
Copy link

@rana01645 rana01645 commented Mar 30, 2022

Summary

When the post_date_gmt value is '0000-00-00 00:00:00' it's always showing posted 1 seconds ago. This fix shows the actual time for the post.

Fixes #

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@CLAassistant
Copy link

CLAassistant commented Mar 30, 2022

CLA assistant check
All committers have signed the CLA.

@westonruter
Copy link
Member

So this is only when a post is a draft and you're previewing, correct?

@@ -26,7 +26,7 @@
sprintf(
/* translators: %s: the human-readable time difference. */
__( '%s ago', 'amp' ),
human_time_diff( $this->get( 'post_publish_timestamp' ), time() )
human_time_diff( $this->get( 'post_publish_timestamp' ), current_time('timestamp') )
Copy link
Member

Choose a reason for hiding this comment

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

This actually used to be current_time( 'timestamp' ) before, but it was changed in 39473e3. Its use was discouraged as of WordPress/WordPress-Coding-Standards#1791.

@@ -305,7 +305,7 @@ private function build_post_publish_timestamp() {
$format = 'U';

if ( empty( $this->post->post_date_gmt ) || '0000-00-00 00:00:00' === $this->post->post_date_gmt ) {
$timestamp = time();
$timestamp = (int) get_the_time('U');
Copy link
Member

Choose a reason for hiding this comment

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

The use of time() came from #5450. Why use get_the_time()?

For one thing, it's not passing the $this->post as context.

@westonruter
Copy link
Member

Also, showing “1 second ago” seems fine for previewing a draft which has no date/time.

@rana01645
Copy link
Author

rana01645 commented Apr 2, 2022

@westonruter It's not for draft only, In my blog I'm getting this error in published post where post_date_gmt value is not added or updated. I don't know it's only my blog specific issue or not. If Wordpress always update the post_date_gmt value for published post then it's fine, otherwise these changes solved the '1 seconds ago' issue for published post without post_date_gmt value.

@westonruter
Copy link
Member

@rana01645 Why would the post_date_gmt not be getting supplied? It should be that once a post is transitioned from the draft status it should get supplied as seen in wp_insert_post():

https://github.com/WordPress/wordpress-develop/blob/671d2caa29fd1dd13aa64be610f3b503d303685b/src/wp-includes/post.php#L4181-L4197

That is, if the status doesn't have date_floating which are limited to (by default):

  • draft
  • pending
  • auto-draft

Are the posts you're seeing this issue in one of those three statuses (stati)? Are you seeing the issue for posts with the publish status?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants