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

WordPress Trac noreply at wordpress.org
Mon Dec 5 07:02:20 UTC 2016


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

Comment (by marco.marsala):

 Replying to [comment:6 jdgrimes]:
 > Replying to [comment:5 marco.marsala]:
 > > I didn't suggest to change `date()` into `gmdate()`.
 > >
 > > The proposed patch would affect only the b`current_time()` and has no
 side effect on `date()` function outside `current_time()` calls, look at
 the code above.
 >
 > I understand that, but if some code outside of WordPress core uses
 `date_default_timezone_set()`, it will affect every call to `date()` in
 WordPress (and plugins), not just the `current_time()` function.
 `current_time()` is not used everywhere that WordPress retrieves the
 current date/time, so other places in the code will still be affected by
 the changed timezone, even though they are expected to be getting the UTC
 time. They would need to be updated to use `current_time()` or `gmdate()`
 in that case.
 >
 It is what I'm saying. The code should use `current_time()`, but
 `current_time()` is bugged if `date_default_timezone_set()` is used. The
 patch aim to fix `current_time()` without adding side effects.
 > In fact, you could avoid changing the timezone in your patch for
 `current_time()`, you could just update it to use `gmdate()` instead of
 `date()`, I think.
 You're completely right.

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


More information about the wp-trac mailing list