[wp-trac] [WordPress Trac] #38940: current_time() expects that date_default_timezone_set is never used

WordPress Trac noreply at wordpress.org
Fri Jun 29 13:20:42 UTC 2018


#38940: current_time() expects that date_default_timezone_set is never used
------------------------------------------------+------------------------
 Reporter:  marco.marsala                       |       Owner:  (none)
     Type:  defect (bug)                        |      Status:  closed
 Priority:  normal                              |   Milestone:
Component:  Date/Time                           |     Version:  4.6.1
 Severity:  normal                              |  Resolution:  duplicate
 Keywords:  has-patch dev-feedback 2nd-opinion  |     Focuses:
------------------------------------------------+------------------------
Changes (by Rarst):

 * status:  new => closed
 * resolution:   => duplicate
 * milestone:  Awaiting Review =>


Old description:

> Currently, the function `current_time()` expects
> `date_default_timezone_set()` is never used.
>
> Inspecting the code of `current_time()` confirmed this, because it
> formats the result using `date()` function (that is affected by
> timezone).
>
> In fact seems Wordpress always resets the timezone to UTC; an `echo
> date_default_timezone_get();` placed at top and at bottom of wp-
> config.php in a clean WordPress setup will prove this.
>
> So using `date_default_timezone_set()` anywhere in theme or plugin code
> will broke `current_time()`.

New description:

 Currently, the function `current_time()` expects
 `date_default_timezone_set()` is never used.

 Inspecting the code of `current_time()` confirmed this, because it formats
 the result using `date()` function (that is affected by timezone).

 In fact seems WordPress always resets the timezone to UTC; an `echo
 date_default_timezone_get();` placed at top and at bottom of wp-config.php
 in a clean WordPress setup will prove this.

 So using `date_default_timezone_set()` anywhere in theme or plugin code
 will broke `current_time()`.

--

Comment:

 Duplicate of #37440.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/38940#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list