[wp-trac] [WordPress Trac] #34435: get_gmt_from_date() returns incorrect value when 'timezone_tz' is 'Europe/London'
WordPress Trac
noreply at wordpress.org
Sun Oct 25 00:53:57 UTC 2015
#34435: get_gmt_from_date() returns incorrect value when 'timezone_tz' is
'Europe/London'
-----------------------------+-----------------------------
Reporter: danielbachhuber | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Date/Time | Version:
Severity: normal | Keywords:
Focuses: |
-----------------------------+-----------------------------
When I use `wp_insert_post()` to create a post when `timezone_tz` is
`Europe/London` [https://github.com/danielbachhuber/year-ago-
today/blob/master/year-ago-today.php#L25-L32 ref], the post gets scheduled
for the future.
`$post_date` is established here:
https://core.trac.wordpress.org/browser/tags/4.3/src/wp-
includes/post.php#L3272
Because `$post_date_gmt` isn't supplied, it's set here:
https://core.trac.wordpress.org/browser/tags/4.3/src/wp-
includes/post.php#L3292
However, `get_gmt_from_date()` returns the same value as its supplied,
when it should return an hour less (as Europe/London respects DST).
`gmdate()` returns the proper GMT date (one hour less) so the post gets
forced to `future` [https://core.trac.wordpress.org/browser/tags/4.3/src
/wp-includes/post.php#L3310 ref]
Here's debug of `get_gmt_from_date()`:
{{{
<?php
$format = 'Y-m-d H:i:s';
$string = '2015-10-25 01:23:08';
$tz = 'Europe/London';
$datetime = date_create( $string, new DateTimeZone( $tz ) );
echo $datetime->format( $format ) . PHP_EOL;
// 2015-10-25 01:23:08
$datetime->setTimezone( new DateTimeZone( 'UTC' ) );
echo $datetime->format( $format ) . PHP_EOL;
// 2015-10-25 01:23:08, but should be 2015-10-25 00:23:08
}}}
Is this a bug in PHP, or how we're using `DateTime`? Tested on PHP 5.6.14,
5.5.9, and 5.5.27
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34435>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list