WordPress.org

Make WordPress Core

Ticket #9285: 9285-4.patch

File 9285-4.patch, 4.0 KB (added by solarissmoke, 4 years ago)
  • formatting.php

     
    15531553/** 
    15541554 * Returns a date in the GMT equivalent. 
    15551555 * 
    1556  * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the 
    1557  * value of the 'gmt_offset' option. Return format can be overridden using the 
    1558  * $format parameter 
     1556 * Requires and returns a date in the Y-m-d H:i:s format. If PHP5 is supported, the  
     1557 * function uses the DateTime and DateTimeZone objects to respect time zone differences in DST.  
     1558 * Otherwise it simply subtracts the value of the 'gmt_offset' option.  
     1559 * Return format can be overridden using the $format parameter. 
    15591560 * 
    15601561 * @since 1.2.0 
    15611562 * 
     
    15651566 * @return string GMT version of the date provided. 
    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/** 
    15751584 * Converts a GMT date into the correct format for the blog. 
    15761585 * 
    1577  * Requires and returns in the Y-m-d H:i:s format. Simply adds the value of 
    1578  * gmt_offset.Return format can be overridden using the $format parameter 
     1586 * Requires and returns in the Y-m-d H:i:s format. If PHP5 is supported, the  
     1587 * function uses the DateTime and DateTimeZone objects to respect time zone differences in DST. 
     1588 * Otherwise it simply adds the value of gmt_offset. 
     1589 * Return format can be overridden using the $format parameter. 
    15791590 * 
    15801591 * @since 1.2.0 
    15811592 * 
    15821593 * @param string $string The date to be converted. 
    15831594 * @param string $format The format string for the returned date (default is Y-m-d H:i:s) 
    1584  * @return string Formatted date relative to the GMT offset. 
     1595 * @return string Formatted date relative to the GMT offset.  
    15851596 */ 
    15861597function 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; 
     1598        if( wp_timezone_supported() ) { 
     1599                // PHP 5 
     1600                $timezone_object = timezone_open( 'GMT' ); 
     1601                $datetime = date_create( $string, $timezone_object ); 
     1602                $timestamp = $datetime->getTimestamp(); 
     1603        } 
     1604        else { 
     1605                // PHP 4 
     1606                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); 
     1607                $timestamp = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] ) + get_option('gmt_offset') * 3600; 
     1608        } 
     1609        return gmdate( $format, $timestamp ); 
    15911610} 
    15921611 
    15931612/** 
  • 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/**