Skip to content

Commit

Permalink
Fix phpcs issues with date() and current_time()
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Nov 11, 2019
1 parent b2a5172 commit 39473e3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
10 changes: 8 additions & 2 deletions back-compat/templates-v0-3/meta-time.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
* @package AMP
*/

/**
* Context.
*
* @var AMP_Post_Template $this
*/

?>
<li class="amp-wp-posted-on">
<time datetime="<?php echo esc_attr( date( 'c', $this->get( 'post_publish_timestamp' ) ) ); ?>">
<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' ) )
human_time_diff( $this->get( 'post_publish_timestamp' ), time() )
)
);
?>
Expand Down
2 changes: 1 addition & 1 deletion bin/create-comments-on-test-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function amp_get_test_comment_entries() {
'comment_parent' => '0',
'comment_author_IP' => '127.0.0.1',
'comment_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
'comment_date' => date( 'Y-m-d H:i:s', $time ),
'comment_date' => gmdate( 'Y-m-d H:i:s', $time ),
'comment_approved' => '1',
];
}
Expand Down
2 changes: 1 addition & 1 deletion includes/class-amp-story-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ public static function the_single_story_card( $args ) {
/* translators: 1: the post author. 2: the amount of time ago. */
esc_html__( '%1$s &#8226; %2$s ago', 'amp' ),
esc_html( $author_display_name ),
esc_html( human_time_diff( get_post_time( 'U', false, $post ), current_time( 'timestamp' ) ) )
esc_html( human_time_diff( get_post_time( 'U', false, $post ), time() ) )
);
?>
</span>
Expand Down
2 changes: 1 addition & 1 deletion includes/cli/class-amp-cli-validation-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ private function get_date_page() {
return null;
}

return add_query_arg( 'year', date( 'Y' ), home_url( '/' ) );
return add_query_arg( 'year', gmdate( 'Y' ), home_url( '/' ) );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions templates/meta-time.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

?>
<div class="amp-wp-meta amp-wp-posted-on">
<time datetime="<?php echo esc_attr( date( 'c', $this->get( 'post_publish_timestamp' ) ) ); ?>">
<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' ) )
human_time_diff( $this->get( 'post_publish_timestamp' ), time() )
)
);
?>
Expand Down
2 changes: 1 addition & 1 deletion tests/php/test-class-amp-cli-validation-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function test_get_search_page() {
* @covers AMP_CLI_Validation_Command::get_date_page()
*/
public function test_get_date_page() {
$year = date( 'Y' );
$year = gmdate( 'Y' );

// Normally, this should return the date page, unless the user has opted out of that template.
$this->assertContains( $year, $this->call_private_method( $this->validation, 'get_date_page' ) );
Expand Down

0 comments on commit 39473e3

Please sign in to comment.