WordPress.org

Make WordPress Core

Ticket #20328: date_fixes.diff

File date_fixes.diff, 4.0 KB (added by scholesmafia, 14 months ago)

Updated diff based on upstream changes

  • wordpress/wp-includes/formatting.php

     
    19061906/** 
    19071907 * Returns a date in the GMT equivalent. 
    19081908 * 
    1909  * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the 
    1910  * value of the 'gmt_offset' option. Return format can be overridden using the 
    1911  * $format parameter. The DateTime and DateTimeZone classes are used to respect 
    1912  * time zone differences in DST. 
     1909 * Requires and returns a date in the Y-m-d H:i:s format. If there is a 
     1910 * timezone_string available, the date is assumed to be in that timezone, 
     1911 * otherwise it simply subtracts the value of the 'gmt_offset' option. Return 
     1912 * format can be overridden using the $format parameter. 
    19131913 * 
    19141914 * @since 1.2.0 
    19151915 * 
     
    19191919 * @return string GMT version of the date provided. 
    19201920 */ 
    19211921function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') { 
    1922         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); 
    1923         if ( ! $matches ) 
    1924                 return date( $format, 0 ); 
    1925  
    19261922        $tz = get_option('timezone_string'); 
    19271923        if ( $tz ) { 
    1928                 date_default_timezone_set( $tz ); 
    1929                 $datetime = date_create( $string ); 
    1930                 if ( ! $datetime ) 
     1924                try { 
     1925                        $datetime = new DateTime( $string , new DateTimeZone($tz) ); 
     1926                } catch (Exception $ex) { 
    19311927                        return date( $format, 0 ); 
    1932  
     1928                } 
    19331929                $datetime->setTimezone( new DateTimeZone('UTC') ); 
    1934                 $offset = $datetime->getOffset(); 
    1935                 $datetime->modify( '+' . $offset / HOUR_IN_SECONDS . ' hours'); 
    1936                 $string_gmt = gmdate($format, $datetime->format('U')); 
    1937  
    1938                 date_default_timezone_set('UTC'); 
     1930                $string_gmt = $datetime->format($format); 
    19391931        } else { 
     1932                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); 
     1933                if ( ! $matches ) { 
     1934                        return date( $format, 0 ); 
     1935                } 
    19401936                $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 
    19411937                $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * HOUR_IN_SECONDS); 
    19421938        } 
     
    19461942/** 
    19471943 * Converts a GMT date into the correct format for the blog. 
    19481944 * 
    1949  * Requires and returns in the Y-m-d H:i:s format. Simply adds the value of 
    1950  * gmt_offset.Return format can be overridden using the $format parameter 
     1945 * Requires and returns a date in the Y-m-d H:i:s format. If there is a 
     1946 * timezone_string available, the returned date is in that timezone, otherwise 
     1947 * it simply adds the value of gmt_offset. Return format can be overridden 
     1948 * using the $format parameter 
    19511949 * 
    19521950 * @since 1.2.0 
    19531951 * 
    19541952 * @param string $string The date to be converted. 
    19551953 * @param string $format The format string for the returned date (default is Y-m-d H:i:s) 
    1956  * @return string Formatted date relative to the GMT offset. 
     1954 * @return string Formatted date relative to the timezone / GMT offset. 
    19571955 */ 
    19581956function get_date_from_gmt($string, $format = 'Y-m-d H:i:s') { 
    1959         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); 
    1960         $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 
    1961         $string_localtime = gmdate($format, $string_time + get_option('gmt_offset') * HOUR_IN_SECONDS); 
     1957        $tz = get_option('timezone_string'); 
     1958        if ( $tz ) { 
     1959                $datetime = new DateTime( $string , new DateTimeZone('UTC') ); 
     1960                $datetime->setTimezone( new DateTimeZone($tz) ); 
     1961                $string_localtime = $datetime->format($format); 
     1962        } else { 
     1963                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); 
     1964                $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 
     1965                $string_localtime = gmdate($format, $string_time + get_option('gmt_offset')*3600); 
     1966        } 
    19621967        return $string_localtime; 
    19631968} 
    19641969 
     
    33833388 */ 
    33843389function wp_unslash( $value ) { 
    33853390        return stripslashes_deep( $value ); 
    3386 } 
    3387  No newline at end of file 
     3391}