Opened 5 years ago
Closed 4 years ago
#47464 closed enhancement (fixed)
Introduce current_datetime() for better time operations
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (3)
Note: See
TracTickets for help on using
tickets.
In 45883: