Skip to content
Permalink
Browse files

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.

git-svn-id: https://develop.svn.wordpress.org/trunk@45883 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
SergeyBiryukov committed Aug 23, 2019
1 parent 67f7d1f commit 1c66cf519b7b91bfa64b0e6b1470c044f40dcdb7
Showing with 12 additions and 1 deletion.
  1. +1 −1 src/wp-admin/includes/dashboard.php
  2. +11 −0 src/wp-includes/functions.php
@@ -860,7 +860,7 @@ function wp_dashboard_recent_posts( $args ) {
echo '<ul>';
$today = current_time( 'Y-m-d' );
$tomorrow = gmdate( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
$tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' );
$year = current_time( 'Y' );
while ( $posts->have_posts() ) {
@@ -79,6 +79,17 @@ function current_time( $type, $gmt = 0 ) {
return $datetime->format( $type );
}
/**
* Retrieves the current time as an object with the timezone from settings.
*
* @since 5.3.0
*
* @return DateTimeImmutable Date and time object.
*/
function current_datetime() {
return new DateTimeImmutable( 'now', wp_timezone() );
}
/**
* Retrieves the timezone from current settings as a string.
*

0 comments on commit 1c66cf5

Please sign in to comment.
You can’t perform that action at this time.