[wp-trac] [WordPress Trac] #25002: get_post_time() doesn't return correct GMT time if date_default_timezone_set is changed from UTC.
WordPress Trac
noreply at wordpress.org
Fri Aug 9 15:19:37 UTC 2013
#25002: get_post_time() doesn't return correct GMT time if
date_default_timezone_set is changed from UTC.
--------------------------+-----------------------------
Reporter: johnregan3 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Date/Time | Version: 3.6
Severity: normal | Keywords: has-patch
--------------------------+-----------------------------
get_post_time() and get_post_modified_time() have a parameter for GMT(UTC)
time. However, they use mysqldate(), which does not take such a parameter
(i.e., mysql2date expects the default time zone to be UTC).
mysql2date() uses strtotime() or date(), both of which return values
relative to the default time zone (date_default_timezone_set()). So, if a
developer changes the default timezone and then requests a GMT date from
get_post_time() or get_post_modified_time(), they will receive an
erroneous return value.
More information here: [http://weston.ruter.net/2013/04/02/do-not-change-
the-default-timezone-from-utc-in-wordpress/]
To reproduce the problem, run the enclosed unit test. It requests a GMT
time from the function twice: once while in GMT, and once in another
timezone (America/Chicago). The two results should be identical because
they both request GMT time, but they are not.
Just to confirm, this problem occurs when all plugins are deactivated and
the default theme is used.
I am submitting two files with this ticket:
1. A Unit Test (mysql2date.php) displaying the faults in mysql2date (and
showing that the new patch fixes the issue).
2. A Patch to fix the bug. This patch has been tested using the Unit
Test above.
The patch begins by adding a fourth optional parameter to mysql2date,
$gmt, which will tell the function that it needs to return a GMT value.
This $gmt variable will be sent from get_post_time() and
get_post_modified_time(). Then, if GMT is requested, the
date_default_timezone_set is set to UTC (WP's default timezone), then
conditional statements instruct mysql2date as to what value to return.
There is more documentation within the patch itself.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25002>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list