Incorrect time/date
-
Publication time on AMP version is +2h forward vs real publication time – could you please check is it bug?
For example:
https://mobirank.pl/2020/09/22/najnowsze-dane-z-okazji-dnia-bez-samochodu/ – here publication time is 6:25 CET
but on https://mobirank.pl/2020/09/22/najnowsze-dane-z-okazji-dnia-bez-samochodu/amp/ at 7:25 CET is displayed 3 hours ago.. it should be 1 hour agoThx in advance
The page I need help with: [log in to see the link]
-
This issue was supposed to be fixed in 2.0.3 via this pull request: https://github.com/ampproject/amp-wp/pull/5335
What timezone is your WordPress install set to?
Do you have any
get_the_dateorget_post_timefilters added?The Schema.org metadata indicates the
publishedDateis2020-09-22T04:25:00+00:00. The post says “3 GODZINY TEMU” (3 hours ago). The current time at this moment is2020-09-22T05:33:19.702Z. So indeed, it should have been 1 hour not 3.Should I check/do something or do you fix it in the future? Thx!
<time datetime="<?php echo esc_attr( date( 'c', $this->get( 'post_publish_timestamp' ) ) ); ?>"> <?php echo esc_html( sprintf( /* translators: %s: the human-readable time difference. */ __( '%s temu', 'amp' ), human_time_diff( $this->get( 'post_publish_timestamp' ), current_time( 'timestamp' ) ) ) ); ?> </time>-
This reply was modified 5 years, 1 month ago by
Łukasz.
I just tried to reproduce the issue by setting my timezone to Warsaw, and when I publish a post it says “X seconds ago” rather than “2 hours ago”.
OK I’ve changed code because I’ve got old code in wp-content/theme/my-theme/amp
Should I change my amp files in theme catalogue after every update?
I see. It looks like your custom template is not correct. Please update
human_time_diff()call to be as follows:With this code is OK:
`<time datetime=”<?php echo esc_attr( gmdate( ‘c’, $this->get( ‘post_publish_timestamp’ ) ) ); ?>”>
<?php
echo esc_html(
sprintf(
/* translators: %s: the human-readable time difference. */
__( ‘%s temu’, ‘amp’ ),
human_time_diff( $this->get( ‘post_publish_timestamp’ ), time() )
)
);
?>
</time>`I’ve deleted timestamp from this:
current_time( 'timestamp' )and time is Ok now-
This reply was modified 5 years, 1 month ago by
Łukasz.
Or you could just replace
current_time( 'timestamp' )withcurrent_time( 'timestamp', true ).The issue is that without the second parameter of
true, a non-GMT/UTC timestamp value is returned.Thank you! I’ve got translated meta-time.php in my theme folder – should I chanege every copied files from new update?
It appears you forked the
meta-time.phptemplate from before 1.5. In that release, we fixed the usage ofcurrent_time(): https://github.com/ampproject/amp-wp/commit/39473e393dba20af83136f4fef8fa4eb70db58f2But since you forked the template, you didn’t get the update.
Generally the legacy AMP templates are not updated each new release, so you shouldn’t have to do that. But it’s not a bad idea to double-check.
In 2.0.1 we reduced one area where forked templates would need to make updates to a forked
style.phpstylesheet: https://github.com/ampproject/amp-wp/pull/5282OK thx
When I replacecurrent_time( 'timestamp' )withcurrent_time( 'timestamp', true ).
there isParse error
: syntax error, unexpected ‘;’, expecting ‘)’ in
/wp-content/themes/leaf/amp/meta-time.php
on line
18W witrynie wystąpił błąd krytyczny.
It looks like you removed the second closing parenthesis.
You can make the whole line look like this:
human_time_diff( $this->get( 'post_publish_timestamp' ), time() )Just copy what is shown here: https://github.com/ampproject/amp-wp/blob/c6312571e38b0b27258eacfd70cec410e9569ba0/templates/meta-time.php#L29
OK thx with
current_time( 'timestamp', true )is ok too
Thx @westonruter so much for your quick help!!!<?php /** * Post date template part. * * @package AMP */ ?> <div class="amp-wp-meta amp-wp-posted-on"> <time datetime="<?php echo esc_attr( gmdate( 'c', $this->get( 'post_publish_timestamp' ) ) ); ?>"> <?php echo esc_html( sprintf( /* translators: %s: the human-readable time difference. */ __( '%s ago', 'amp' ), human_time_diff( $this->get( 'post_publish_timestamp' ), current_time( 'timestamp', true ) ) ) ); ?> </time> </div> -
This reply was modified 5 years, 1 month ago by
The topic ‘Incorrect time/date’ is closed to new replies.