Date/Time: Reduce explicit local current_time( 'timestamp' ) usage in favor of native PHP functions.

Timestamps don't carry any timezone information, using the intended format directly simplifies the logic and makes the code less confusing.

Props Rarst, jdgrimes.
See #40657.

git-svn-id: https://develop.svn.wordpress.org/trunk@44809 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-03-07 09:11:37 +00:00
parent 79a3abcb2a
commit 4b10390b7d
7 changed files with 31 additions and 32 deletions

View File

@ -1464,7 +1464,7 @@ function wp_ajax_add_meta() {
$post_data['post_ID'] = $pid; $post_data['post_ID'] = $pid;
$post_data['post_type'] = $post->post_type; $post_data['post_type'] = $post->post_type;
$post_data['post_status'] = 'draft'; $post_data['post_status'] = 'draft';
$now = current_time( 'timestamp', 1 ); $now = time();
/* translators: 1: Post creation date, 2: Post creation time */ /* translators: 1: Post creation date, 2: Post creation time */
$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) ); $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) );

View File

@ -858,8 +858,9 @@ function wp_dashboard_recent_posts( $args ) {
echo '<ul>'; echo '<ul>';
$today = date( 'Y-m-d', current_time( 'timestamp' ) ); $today = current_time( 'Y-m-d' );
$tomorrow = date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) ); $tomorrow = gmdate( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
$year = current_time( 'Y' );
while ( $posts->have_posts() ) { while ( $posts->have_posts() ) {
$posts->the_post(); $posts->the_post();
@ -869,7 +870,7 @@ function wp_dashboard_recent_posts( $args ) {
$relative = __( 'Today' ); $relative = __( 'Today' );
} elseif ( date( 'Y-m-d', $time ) == $tomorrow ) { } elseif ( date( 'Y-m-d', $time ) == $tomorrow ) {
$relative = __( 'Tomorrow' ); $relative = __( 'Tomorrow' );
} elseif ( date( 'Y', $time ) !== date( 'Y', current_time( 'timestamp' ) ) ) { } elseif ( date( 'Y', $time ) !== $year ) {
/* translators: date and time format for recent posts on the dashboard, from a different calendar year, see https://secure.php.net/date */ /* translators: date and time format for recent posts on the dashboard, from a different calendar year, see https://secure.php.net/date */
$relative = date_i18n( __( 'M jS Y' ), $time ); $relative = date_i18n( __( 'M jS Y' ), $time );
} else { } else {

View File

@ -774,20 +774,19 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
// todo: Remove this? // todo: Remove this?
// echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />'; // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
$time_adj = current_time( 'timestamp' );
$post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date; $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
$jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj ); $jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' );
$mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj ); $mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' );
$aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj ); $aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' );
$hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj ); $hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' );
$mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj ); $mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' );
$ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj ); $ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' );
$cur_jj = gmdate( 'd', $time_adj ); $cur_jj = current_time( 'd' );
$cur_mm = gmdate( 'm', $time_adj ); $cur_mm = current_time( 'm' );
$cur_aa = gmdate( 'Y', $time_adj ); $cur_aa = current_time( 'Y' );
$cur_hh = gmdate( 'H', $time_adj ); $cur_hh = current_time( 'H' );
$cur_mn = gmdate( 'i', $time_adj ); $cur_mn = current_time( 'i' );
$month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n"; $month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
for ( $i = 1; $i < 13; $i = $i + 1 ) { for ( $i = 1; $i < 13; $i = $i + 1 ) {

View File

@ -1392,7 +1392,7 @@ abstract class WP_Privacy_Requests_Table extends WP_List_Table {
return ''; return '';
} }
$time_diff = current_time( 'timestamp', true ) - $timestamp; $time_diff = time() - $timestamp;
if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) { if ( $time_diff >= 0 && $time_diff < DAY_IN_SECONDS ) {
/* translators: human readable timestamp */ /* translators: human readable timestamp */

View File

@ -2005,7 +2005,6 @@ function get_calendar( $initial = true, $echo = true ) {
} }
// week_begins = 0 stands for Sunday // week_begins = 0 stands for Sunday
$week_begins = (int) get_option( 'start_of_week' ); $week_begins = (int) get_option( 'start_of_week' );
$ts = current_time( 'timestamp' );
// Let's figure out when we are // Let's figure out when we are
if ( ! empty( $monthnum ) && ! empty( $year ) ) { if ( ! empty( $monthnum ) && ! empty( $year ) ) {
@ -2025,8 +2024,8 @@ function get_calendar( $initial = true, $echo = true ) {
$thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 ); $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 );
} }
} else { } else {
$thisyear = gmdate( 'Y', $ts ); $thisyear = current_time( 'Y' );
$thismonth = gmdate( 'm', $ts ); $thismonth = current_time( 'm' );
} }
$unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear ); $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear );
@ -2136,9 +2135,9 @@ function get_calendar( $initial = true, $echo = true ) {
} }
$newrow = false; $newrow = false;
if ( $day == gmdate( 'j', $ts ) && if ( $day == current_time( 'j' ) &&
$thismonth == gmdate( 'm', $ts ) && $thismonth == current_time( 'm' ) &&
$thisyear == gmdate( 'Y', $ts ) ) { $thisyear == current_time( 'Y' ) ) {
$calendar_output .= '<td id="today">'; $calendar_output .= '<td id="today">';
} else { } else {
$calendar_output .= '<td>'; $calendar_output .= '<td>';

View File

@ -470,7 +470,7 @@ function get_attachment_link( $post = null, $leavename = false ) {
function get_year_link( $year ) { function get_year_link( $year ) {
global $wp_rewrite; global $wp_rewrite;
if ( ! $year ) { if ( ! $year ) {
$year = gmdate( 'Y', current_time( 'timestamp' ) ); $year = current_time( 'Y' );
} }
$yearlink = $wp_rewrite->get_year_permastruct(); $yearlink = $wp_rewrite->get_year_permastruct();
if ( ! empty( $yearlink ) ) { if ( ! empty( $yearlink ) ) {
@ -505,10 +505,10 @@ function get_year_link( $year ) {
function get_month_link( $year, $month ) { function get_month_link( $year, $month ) {
global $wp_rewrite; global $wp_rewrite;
if ( ! $year ) { if ( ! $year ) {
$year = gmdate( 'Y', current_time( 'timestamp' ) ); $year = current_time( 'Y' );
} }
if ( ! $month ) { if ( ! $month ) {
$month = gmdate( 'm', current_time( 'timestamp' ) ); $month = current_time( 'm' );
} }
$monthlink = $wp_rewrite->get_month_permastruct(); $monthlink = $wp_rewrite->get_month_permastruct();
if ( ! empty( $monthlink ) ) { if ( ! empty( $monthlink ) ) {
@ -546,13 +546,13 @@ function get_month_link( $year, $month ) {
function get_day_link( $year, $month, $day ) { function get_day_link( $year, $month, $day ) {
global $wp_rewrite; global $wp_rewrite;
if ( ! $year ) { if ( ! $year ) {
$year = gmdate( 'Y', current_time( 'timestamp' ) ); $year = current_time( 'Y' );
} }
if ( ! $month ) { if ( ! $month ) {
$month = gmdate( 'm', current_time( 'timestamp' ) ); $month = current_time( 'm' );
} }
if ( ! $day ) { if ( ! $day ) {
$day = gmdate( 'j', current_time( 'timestamp' ) ); $day = current_time( 'j' );
} }
$daylink = $wp_rewrite->get_day_permastruct(); $daylink = $wp_rewrite->get_day_permastruct();

View File

@ -518,7 +518,7 @@ function wpmu_validate_user_signup( $user_name, $user_email ) {
$signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) ); $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name ) );
if ( $signup != null ) { if ( $signup != null ) {
$registered_at = mysql2date( 'U', $signup->registered ); $registered_at = mysql2date( 'U', $signup->registered );
$now = current_time( 'timestamp', true ); $now = time();
$diff = $now - $registered_at; $diff = $now - $registered_at;
// If registered more than two days ago, cancel registration and let this signup go through. // If registered more than two days ago, cancel registration and let this signup go through.
if ( $diff > 2 * DAY_IN_SECONDS ) { if ( $diff > 2 * DAY_IN_SECONDS ) {
@ -530,7 +530,7 @@ function wpmu_validate_user_signup( $user_name, $user_email ) {
$signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) ); $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE user_email = %s", $user_email ) );
if ( $signup != null ) { if ( $signup != null ) {
$diff = current_time( 'timestamp', true ) - mysql2date( 'U', $signup->registered ); $diff = time() - mysql2date( 'U', $signup->registered );
// If registered more than two days ago, cancel registration and let this signup go through. // If registered more than two days ago, cancel registration and let this signup go through.
if ( $diff > 2 * DAY_IN_SECONDS ) { if ( $diff > 2 * DAY_IN_SECONDS ) {
$wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) );
@ -688,7 +688,7 @@ function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) {
// Has someone already signed up for this domain? // Has someone already signed up for this domain?
$signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path ) ); // TODO: Check email too? $signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path ) ); // TODO: Check email too?
if ( ! empty( $signup ) ) { if ( ! empty( $signup ) ) {
$diff = current_time( 'timestamp', true ) - mysql2date( 'U', $signup->registered ); $diff = time() - mysql2date( 'U', $signup->registered );
// If registered more than two days ago, cancel registration and let this signup go through. // If registered more than two days ago, cancel registration and let this signup go through.
if ( $diff > 2 * DAY_IN_SECONDS ) { if ( $diff > 2 * DAY_IN_SECONDS ) {
$wpdb->delete( $wpdb->delete(