WordPress.org

Make WordPress Core

Opened 2 weeks ago

Last modified 2 weeks ago

#47464 reviewing enhancement

Introduce current_datetime() for better time operations

Reported by: Rarst Owned by: SergeyBiryukov
Milestone: 5.3 Priority: normal
Severity: minor Version:
Component: Date/Time Keywords: has-patch
Focuses: Cc:

Description

WordPress uses current_time() function to refer to the current moment of date and time. Timestamps issues in it aside, it's not friendly to time operations, leading to convoluted and fragile code when time needs to be shifted from current, for example:

<?php
$tomorrow = gmdate( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );

The patch introduces current_datetime() analogue that returns proper DateTimeImmutable representation of current moment in time, open to a more flexible and reliable use:

<?php
tomorrow = current_datetime()->modify('+1 day')->format('Y-m-d');

Patch needs wp_timezone() merged, see #24730

Parent issue #40657

Attachments (1)

current-datetime.patch (1.3 KB) - added by Rarst 2 weeks ago.

Download all attachments as: .zip

Change History (2)

#1 @SergeyBiryukov
2 weeks ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing
Note: See TracTickets for help on using tickets.