WordPress.org

Make WordPress Core

Ticket #9285: get_gmt_offset.patch

File get_gmt_offset.patch, 3.2 KB (added by solarissmoke, 10 years ago)

Change behaviour of get_date_from_gmt and get_gmt_from_date to use a new function get_gmt_offset

  • formatting.php

     
    15671567function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
    15681568        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);
    15691569        $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
    1570         $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600);
     1570        $string_gmt = gmdate($format, $string_time - get_gmt_offset($string_time) * 3600);
    15711571        return $string_gmt;
    15721572}
    15731573
     
    15861586function get_date_from_gmt($string, $format = 'Y-m-d H:i:s') {
    15871587        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);
    15881588        $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
    1589         $string_localtime = gmdate($format, $string_time + get_option('gmt_offset')*3600);
     1589        $string_localtime = gmdate($format, $string_time + get_gmt_offset($string_time)*3600);
    15901590        return $string_localtime;
    15911591}
    15921592
  • functions.php

     
    37783778 *
    37793779 * @return float|bool
    37803780 */
    3781 function wp_timezone_override_offset() {
     3781function wp_timezone_override_offset($timestamp = 'now') {
    37823782        if ( !wp_timezone_supported() ) {
    37833783                return false;
    37843784        }
    37853785        if ( !$timezone_string = get_option( 'timezone_string' ) ) {
    37863786                return false;
    37873787        }
     3788       
     3789        if('now' == $timestamp) $timestamp = time();
    37883790
    37893791        $timezone_object = timezone_open( $timezone_string );
    3790         $datetime_object = date_create();
     3792        $datetime_object = date_create($timestamp);
    37913793        if ( false === $timezone_object || false === $datetime_object ) {
    37923794                return false;
    37933795        }
     
    41594161        @header( 'X-Content-Type-Options: nosniff' );
    41604162}
    41614163
     4164/**
     4165 * Get the gmt_offset at a specified time. This is different from using get_option('gmt_offset')
     4166 * because it lets you specify a time in the past or future (where the daylight savings may be different
     4167 * from the current time. Defaults to the gmt_offset option if timezone support doesn't exist, or if the
     4168 * timestamp argument is omitted.
     4169 *
     4170 * @since
     4171 * @return float
     4172 */
     4173function get_gmt_offset($timestamp = 'now') {
     4174        // if no timestamp is supplied, or if PHP doesn't support fancy timezone handling, just get the option
     4175        if('now' == $timestamp || !wp_timezone_supported() || !get_option( 'timezone_string' ) )
     4176                return get_option( 'gmt_offset' );
     4177       
     4178        return wp_timezone_override_offset($timestamp);
     4179}
    41624180?>
  • post.php

     
    41084108 */
    41094109function _future_post_hook( $deprecated = '', $post ) {
    41104110        wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
    4111         wp_schedule_single_event( strtotime( $post->post_date_gmt. ' GMT' ), 'publish_future_post', array( $post->ID ) );
     4111        wp_schedule_single_event( get_gmt_from_date( $post->post_date ), 'publish_future_post', array( $post->ID ) );
    41124112}
    41134113
    41144114/**