WordPress.org

Make WordPress Core

Changeset 45883


Ignore:
Timestamp:
08/23/2019 01:11:22 AM (4 weeks ago)
Author:
SergeyBiryukov
Message:

Date/Time: Introduce current_datetime() for better time operations.

Returning a DateTimeImmutable representation of the current moment in time, this allows for a more flexible and reliable use than current_time() provides.

Props Rarst.
Fixes #47464.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/dashboard.php

    r45674 r45883  
    861861
    862862        $today    = current_time( 'Y-m-d' );
    863         $tomorrow = gmdate( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
     863        $tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' );
    864864        $year     = current_time( 'Y' );
    865865
  • trunk/src/wp-includes/functions.php

    r45882 r45883  
    7878
    7979    return $datetime->format( $type );
     80}
     81
     82/**
     83 * Retrieves the current time as an object with the timezone from settings.
     84 *
     85 * @since 5.3.0
     86 *
     87 * @return DateTimeImmutable Date and time object.
     88 */
     89function current_datetime() {
     90    return new DateTimeImmutable( 'now', wp_timezone() );
    8091}
    8192
Note: See TracChangeset for help on using the changeset viewer.