[wp-trac] [WordPress Trac] #47464: Introduce current_datetime() for better time operations

WordPress Trac noreply at wordpress.org
Mon Jun 3 06:04:07 UTC 2019


#47464: Introduce current_datetime() for better time operations
-------------------------+-----------------------------
 Reporter:  Rarst        |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Date/Time    |    Version:
 Severity:  minor        |   Keywords:  has-patch
  Focuses:               |
-------------------------+-----------------------------
 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
 <?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
 <?php
 tomorrow = current_datetime()->modify('+1 day')->format('Y-m-d');
 }}}

 Patch needs `wp_timezone()` merged, see #24730

 Parent issue #40657

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47464>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list