Make WordPress Core


Ignore:
Timestamp:
10/20/2015 06:07:45 AM (10 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r35252 r35284  
    612612            . '(?:]]>)?';   // End of comment. If not found, match all input.
    613613
    614         $escaped = 
     614        $escaped =
    615615              '(?='           // Is the element escaped?
    616616            .    '!--'
     
    25882588    if ( $tz ) {
    25892589        $datetime = date_create( $string, new DateTimeZone( $tz ) );
    2590         if ( ! $datetime )
     2590        if ( ! $datetime ) {
    25912591            return gmdate( $format, 0 );
     2592        }
    25922593        $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
    25932594        $string_gmt = $datetime->format( $format );
    25942595    } else {
    2595         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 ) )
    2596             return gmdate( $format, 0 );
     2596        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 ) ) {
     2597            $datetime = strtotime( $string );
     2598            if ( false === $datetime ) {
     2599                return gmdate( $format, 0 );
     2600            }
     2601            return gmdate( $format, $datetime );
     2602        }
    25972603        $string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] );
    25982604        $string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
     
    38773883 * This is similar to `array_walk_recursive()` but acts upon objects too.
    38783884 *
    3879  * @since 4.4.0 
    3880  * 
     3885 * @since 4.4.0
     3886 *
    38813887 * @param mixed    $value    The array, object, or scalar.
    3882  * @param callable $function The function to map onto $value.
     3888 * @param callable $callback The function to map onto $value.
    38833889 * @return The value with the callback applied to all non-arrays and non-objects inside it.
    38843890 */
Note: See TracChangeset for help on using the changeset viewer.