Ticket #20328: date_fixes.diff
File date_fixes.diff, 4.0 KB (added by , 12 years ago) |
---|
-
wordpress/wp-includes/formatting.php
1906 1906 /** 1907 1907 * Returns a date in the GMT equivalent. 1908 1908 * 1909 * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the1910 * value of the 'gmt_offset' option. Return format can be overridden using the1911 * $format parameter. The DateTime and DateTimeZone classes are used to respect1912 * 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. 1913 1913 * 1914 1914 * @since 1.2.0 1915 1915 * … … 1919 1919 * @return string GMT version of the date provided. 1920 1920 */ 1921 1921 function 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 1926 1922 $tz = get_option('timezone_string'); 1927 1923 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) { 1931 1927 return date( $format, 0 ); 1932 1928 } 1933 1929 $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); 1939 1931 } 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 } 1940 1936 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 1941 1937 $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * HOUR_IN_SECONDS); 1942 1938 } … … 1946 1942 /** 1947 1943 * Converts a GMT date into the correct format for the blog. 1948 1944 * 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 1951 1949 * 1952 1950 * @since 1.2.0 1953 1951 * 1954 1952 * @param string $string The date to be converted. 1955 1953 * @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. 1957 1955 */ 1958 1956 function 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 } 1962 1967 return $string_localtime; 1963 1968 } 1964 1969 … … 3383 3388 */ 3384 3389 function wp_unslash( $value ) { 3385 3390 return stripslashes_deep( $value ); 3386 } 3387 No newline at end of file 3391 }