[wp-trac] [WordPress Trac] #9588: time() is not GMT time()

WordPress Trac wp-trac at lists.automattic.com
Mon Jan 4 23:13:14 UTC 2010

#9588: time() is not GMT time()
  Reporter:  Denis-de-Bernardy  |        Type:  defect (bug)           
    Status:  reopened           |    Priority:  normal                 
 Milestone:  3.0                |   Component:  Date/Time              
   Version:  2.8                |    Severity:  normal                 
Resolution:                     |    Keywords:  has-patch needs-testing

Comment(by ryan):

 Replying to [comment:36 Otto42]:
 > Replying to [comment:35 ryan]:
 > > Alternatively, always set the default timezone to UTC and remove the
 default timezone set in wp_timezone_override_offset().  Then everything
 behaves as before.
 > Before was broken. It's only by setting the correct default timezone
 that I can get correct behavior.

 Before as in the PHP4 case, which worked. Forcing the default timezone to
 UTC brings us back to what has always worked for us. We can always add our
 offset since times are UTC.  This requires less code churn but probably
 isn't the best way forward.

 > Short version is that the default timezone should be set to the
 timezone_string (if set) at the earliest possible moment. Anywhere in core
 that is expecting the current GMT should be adjusted to use better
 functions to get that time, instead of using time() calls. current_time()
 is the obvious choice, it could be adjusted to behave appropriately.

 The latest patch sets it early. However, there's a choice of setting it to
 UTC and continuing to do our offsets as mentioned above or setting it to
 timezone_string and conditionally doing the offsets only if the default
 timezone isn't set or supported by the PHP version.  The patch sets it to
 timezone_string and conditionally adds the offset for older versions but
 omits adding it for newer versions with a proper timezone set.

 > And that's basically that.
 > Note that time() should always returns an absolute value of seconds in
 GMT. It is supposed to be unaffected by timezone settings. The problem is
 that sometimes we apply offset to it and sometimes not. We just need to
 remember to apply the offset correctly.
 > What cases still exist that create incorrect results?

 Indeed, time() is independent of the timezone.  The trouble is finding all
 of the little places where we were relying on the old behavior and making
 them work with both the old and new ways. I think I've got most of them.

Ticket URL: <http://core.trac.wordpress.org/ticket/9588#comment:37>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software

More information about the wp-trac mailing list