Formatting: allow date strings to be passed to get_gmt_from_date(), instead of requiring 'Y-m-d H:i:s'.

Adds unit tests.

Props pbearne.
Fixes #34279.

Built from https://develop.svn.wordpress.org/trunk@35284


git-svn-id: http://core.svn.wordpress.org/trunk@35250 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-10-20 06:08:25 +00:00
parent f4cc7b3de8
commit afe975d754
2 changed files with 14 additions and 8 deletions

View File

@ -611,7 +611,7 @@ function get_html_split_regex() {
. ')*+' // Loop possessively.
. '(?:]]>)?'; // End of comment. If not found, match all input.
$escaped =
$escaped =
'(?=' // Is the element escaped?
. '!--'
. '|'
@ -2587,13 +2587,19 @@ function get_gmt_from_date( $string, $format = 'Y-m-d H:i:s' ) {
$tz = get_option( 'timezone_string' );
if ( $tz ) {
$datetime = date_create( $string, new DateTimeZone( $tz ) );
if ( ! $datetime )
if ( ! $datetime ) {
return gmdate( $format, 0 );
}
$datetime->setTimezone( new DateTimeZone( 'UTC' ) );
$string_gmt = $datetime->format( $format );
} else {
if ( ! 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 ) )
return gmdate( $format, 0 );
if ( ! 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 ) ) {
$datetime = strtotime( $string );
if ( false === $datetime ) {
return gmdate( $format, 0 );
}
return gmdate( $format, $datetime );
}
$string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] );
$string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
}
@ -3876,10 +3882,10 @@ function sanitize_option( $option, $value ) {
*
* This is similar to `array_walk_recursive()` but acts upon objects too.
*
* @since 4.4.0
*
* @since 4.4.0
*
* @param mixed $value The array, object, or scalar.
* @param callable $function The function to map onto $value.
* @param callable $callback The function to map onto $value.
* @return The value with the callback applied to all non-arrays and non-objects inside it.
*/
function map_deep( $value, $callback ) {

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-35283';
$wp_version = '4.4-alpha-35284';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.