From dacd1c56231eb7d5fa807456b100f2b67009f3cd Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Thu, 6 May 2010 20:40:29 +0000 Subject: [PATCH] Improve cross DST future post publishing behaviour to try and publish at the correct time if we have PHP5 timezone support available to help. Fixes #9285 props technosailor. git-svn-id: https://develop.svn.wordpress.org/trunk@14487 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/formatting.php | 22 +++++++++++++++++++--- wp-includes/post.php | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index b2c5407cfc..8710b7159c 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -1553,7 +1553,8 @@ function wp_iso_descrambler($string) { * * 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. If PHP5 is supported, the function uses the DateTime and + * DateTimeZone objects to respect time zone differences in DST. * * @since 1.2.0 * @@ -1564,8 +1565,23 @@ function wp_iso_descrambler($string) { */ 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); - $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); + $tz = get_option('timezone_string'); + if( class_exists('DateTime') && $tz ) { + //PHP5 + 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 { + //PHP4 + $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; } diff --git a/wp-includes/post.php b/wp-includes/post.php index 0254554bfb..3c7a025c8b 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -4138,7 +4138,7 @@ function _transition_post_status($new_status, $old_status, $post) { */ function _future_post_hook( $deprecated = '', $post ) { wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); - wp_schedule_single_event( strtotime( $post->post_date_gmt. ' GMT' ), 'publish_future_post', array( $post->ID ) ); + wp_schedule_single_event( get_gmt_from_date( $post->post_date ) . ' GMT', 'publish_future_post', array( $post->ID ) ); } /**