Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    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_date or get_post_time filters added?

    Plugin Author Weston Ruter

    (@westonruter)

    The Schema.org metadata indicates the publishedDate is 2020-09-22T04:25:00+00:00. The post says “3 GODZINY TEMU” (3 hours ago). The current time at this moment is 2020-09-22T05:33:19.702Z. So indeed, it should have been 1 hour not 3.

    Thread Starter ?ukasz

    (@lumay)

    Should I check/do something or do you fix it in the future? Thx!

    Thread Starter ?ukasz

    (@lumay)

    	<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 4 years, 6 months ago by ?ukasz.
    Plugin Author Weston Ruter

    (@westonruter)

    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”.

    Thread Starter ?ukasz

    (@lumay)

    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?

    Plugin Author Weston Ruter

    (@westonruter)

    I see. It looks like your custom template is not correct. Please update human_time_diff() call to be as follows:

    https://github.com/ampproject/amp-wp/blob/c6312571e38b0b27258eacfd70cec410e9569ba0/templates/meta-time.php#L29

    Thread Starter ?ukasz

    (@lumay)

    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 4 years, 6 months ago by ?ukasz.
    Plugin Author Weston Ruter

    (@westonruter)

    Or you could just replace current_time( 'timestamp' ) with current_time( 'timestamp', true ).

    The issue is that without the second parameter of true, a non-GMT/UTC timestamp value is returned.

    Thread Starter ?ukasz

    (@lumay)

    Thank you! I’ve got translated meta-time.php in my theme folder – should I chanege every copied files from new update?

    Plugin Author Weston Ruter

    (@westonruter)

    It appears you forked the meta-time.php template from before 1.5. In that release, we fixed the usage of current_time(): https://github.com/ampproject/amp-wp/commit/39473e393dba20af83136f4fef8fa4eb70db58f2

    But since you forked the template, you didn’t get the update.

    Plugin Author Weston Ruter

    (@westonruter)

    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.php stylesheet: https://github.com/ampproject/amp-wp/pull/5282

    Thread Starter ?ukasz

    (@lumay)

    OK thx
    When I replace current_time( 'timestamp' ) with current_time( 'timestamp', true ).
    there is

    Parse error
    : syntax error, unexpected ‘;’, expecting ‘)’ in
    /wp-content/themes/leaf/amp/meta-time.php
    on line
    18

    W witrynie wyst?pi? b??d krytyczny.

    Plugin Author Weston Ruter

    (@westonruter)

    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

    Thread Starter ?ukasz

    (@lumay)

    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>
Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Incorrect time/date’ is closed to new replies.