[wp-trac] [WordPress Trac] #20328: get_date_from_gmt assumes current gmt_offset is appropriate

WordPress Trac noreply at wordpress.org
Tue Mar 5 12:08:02 UTC 2013


#20328: get_date_from_gmt assumes current gmt_offset is appropriate
---------------------------+------------------------------
 Reporter:  scottconnerly  |       Owner:
     Type:  defect (bug)   |      Status:  reopened
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Date/Time      |     Version:
 Severity:  normal         |  Resolution:
 Keywords:  has-patch      |
---------------------------+------------------------------
Changes (by scholesmafia):

 * keywords:  has-patch needs-unit-tests => has-patch


Comment:

 Test case added.

 The original phpdoc for the function hints at the bug: "Simply adds the
 value of gmt_offset." This is not sufficient to be DST aware. The point of
 DST is that gmt_offset changes throughout the year, so simply adding the
 offset to any date will be incorrect for ~50% of dates.

 Note that the dual function `get_gmt_from_date` uses the `timezone_string`
 option and the `DateTime` class to properly respect the timezone, as
 alluded to in #20398. This is why the second test
 `test_dst_respected_getting_gmt_date` passes.

 The patch to `get_date_from_gmt` adds the same functionality, so that the
 `timezone_string` is used to convert the GMT date into a date local to
 that timezone, which respects DST where relevant. The patch only alters
 `get_gmt_from_date` to unify the logic between both functions and use
 `DateTime` properly.

 Note that both functions fall back to the naïve approach of adding or
 subtracting `gmt_offset` where the `timezone_string` option is not
 available.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20328#comment:11>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list