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.
Built from https://develop.svn.wordpress.org/trunk@44809


git-svn-id: http://core.svn.wordpress.org/trunk@44641 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2019-03-07 09:12:51 +00:00
parent 2d58d57e38
commit 5658305b1c
12 changed files with 393 additions and 33 deletions

View File

@@ -1464,7 +1464,7 @@ function wp_ajax_add_meta() {
$post_data['post_ID'] = $pid;
$post_data['post_type'] = $post->post_type;
$post_data['post_status'] = 'draft';
$now = current_time( 'timestamp', 1 );
$now = 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 ) );

View File

@@ -858,8 +858,9 @@ function wp_dashboard_recent_posts( $args ) {
echo '<ul>';
$today = date( 'Y-m-d', current_time( 'timestamp' ) );
$tomorrow = date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
$today = current_time( 'Y-m-d' );
$tomorrow = gmdate( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
$year = current_time( 'Y' );
while ( $posts->have_posts() ) {
$posts->the_post();
@@ -869,7 +870,7 @@ function wp_dashboard_recent_posts( $args ) {
$relative = __( 'Today' );
} elseif ( date( 'Y-m-d', $time ) == $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 */
$relative = date_i18n( __( 'M jS Y' ), $time );
} else {

View File

@@ -774,20 +774,19 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
// 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 />';
$time_adj = current_time( 'timestamp' );
$post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
$jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
$mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
$aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
$hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
$mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
$ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
$jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' );
$mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' );
$aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' );
$hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' );
$mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' );
$ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' );
$cur_jj = gmdate( 'd', $time_adj );
$cur_mm = gmdate( 'm', $time_adj );
$cur_aa = gmdate( 'Y', $time_adj );
$cur_hh = gmdate( 'H', $time_adj );
$cur_mn = gmdate( 'i', $time_adj );
$cur_jj = current_time( 'd' );
$cur_mm = current_time( 'm' );
$cur_aa = current_time( 'Y' );
$cur_hh = current_time( 'H' );
$cur_mn = current_time( 'i' );
$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 ) {

View File

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