Make WordPress Core

Ticket #9285: 9285-4.2.patch

File 9285-4.2.patch, 3.1 KB (added by solarissmoke, 14 years ago)
  • formatting.php

     
    15621562 * @uses get_option() to retrieve the the value of 'gmt_offset'.
    15631563 * @param string $string The date to be converted.
    15641564 * @param string $format The format string for the returned date (default is Y-m-d H:i:s)
    1565  * @return string GMT version of the date provided.
     1565 * @return string GMT version of the date provided. If PHP5 is supported, the function uses the DateTime and
     1566 * DateTimeZone objects to respect time zone differences in DST.
    15661567 */
    15671568function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
    1568         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);
    1569         $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);
    1571         return $string_gmt;
     1569        if( wp_timezone_supported() && $tz_string = get_option( 'timezone_string' ) ) {
     1570                // PHP 5
     1571                $tz_object = timezone_open( $tz_string );
     1572                $datetime = date_create( $string, $tz_object );
     1573                $timestamp = $datetime->getTimestamp();
     1574        }
     1575        else {
     1576                // PHP 4
     1577                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);
     1578                $timestamp = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] ) - get_option('gmt_offset') * 3600;
     1579        }
     1580        return gmdate( $format, $timestamp );
    15721581}
    15731582
    15741583/**
     
    15841593 * @return string Formatted date relative to the GMT offset.
    15851594 */
    15861595function get_date_from_gmt($string, $format = 'Y-m-d H:i:s') {
    1587         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);
    1588         $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);
    1590         return $string_localtime;
     1596        if( wp_timezone_supported() ) {
     1597                // PHP 5
     1598                $timezone_object = timezone_open( 'GMT' );
     1599                $datetime = date_create( $string, $timezone_object );
     1600                $timestamp = $datetime->getTimestamp();
     1601        }
     1602        else {
     1603                // PHP 4
     1604                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);
     1605                $timestamp = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]) + get_option('gmt_offset') * 3600;
     1606        }
     1607        return gmdate($format, $timestamp);
    15911608}
    15921609
    15931610/**
  • post.php

     
    41124112 */
    41134113function _future_post_hook( $deprecated = '', $post ) {
    41144114        wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
    4115         wp_schedule_single_event( strtotime( $post->post_date_gmt. ' GMT' ), 'publish_future_post', array( $post->ID ) );
     4115        wp_schedule_single_event( get_gmt_from_date( $post->post_date, 'U' ), 'publish_future_post', array( $post->ID ) );
    41164116}
    41174117
    41184118/**