Ensure post_publish_timestamp in AMP_Post_Template is UTC for human_time_diff() #5335
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
As reported in a support forum topic, the relative publish time displayed on the legacy post template is incorrect when the timezone is not UTC.
For example, on my site I have the timezone set to
America/Los_Angeles
. Nevertheless, when I publish my post and I immediately view the legacy AMP post template, I see "7 hours ago". This is because my timezone is UTC-7. The problem is that thepost_publish_timestamp
was being populated withget_the_date( 'U', $this->post )
which returns a non-GMT “Unix timestamp” (which AFAIK doesn't even make sense, since this value should be timezone-independent). Nevertheless, sinceget_the_date( 'U', $this->post )
is getting the blog's timezone offset, it then fails to render the right result in the template:amp-wp/templates/meta-time.php
Lines 25 to 31 in 5191d35
Here
time()
is the Unix timestamp of seconds since January 1, 1970 00:00:00 UTC. But$post_publish_timestamp
is actually 7 hours before that on my install.The fix is to not call
get_the_date()
directly, but to call the underlyingget_post_time()
which does allow you to specifically request the GMT time.Since previously
get_the_date()
was used, I figured it would be good to continue applyingget_the_date
filters so that they wouldn't break if sites were using them.Checklist