From b2c2e302beaa5638e8db4883422d109b09662544 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 18 May 2011 18:56:42 +0000 Subject: [PATCH] Revert part of [17920]. Support for empty tz must remain. Props johnjamesjacoby. fixes #17448 git-svn-id: http://svn.automattic.com/wordpress/trunk@17958 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index a7a4b5338..631810f95 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -1588,7 +1588,8 @@ function _wp_iso_convert( $match ) { * * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the * value of the 'gmt_offset' option. Return format can be overridden using the - * $format parameter. + * $format parameter. The DateTime and DateTimeZone classes are used to respect + * time zone differences in DST. * * @since 1.2.0 * @@ -1600,13 +1601,19 @@ function _wp_iso_convert( $match ) { function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') { preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches); $tz = get_option('timezone_string'); - date_default_timezone_set( $tz ); - $datetime = new DateTime( $string ); - $datetime->setTimezone( new DateTimeZone('UTC') ); - $offset = $datetime->getOffset(); - $datetime->modify( '+' . $offset / 3600 . ' hours'); - $string_gmt = gmdate($format, $datetime->format('U')); - date_default_timezone_set('UTC'); + if ( $tz ) { + date_default_timezone_set( $tz ); + $datetime = new DateTime( $string ); + $datetime->setTimezone( new DateTimeZone('UTC') ); + $offset = $datetime->getOffset(); + $datetime->modify( '+' . $offset / 3600 . ' hours'); + $string_gmt = gmdate($format, $datetime->format('U')); + + date_default_timezone_set('UTC'); + } else { + $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); + $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600); + } return $string_gmt; }