Make WordPress Core

Ticket #34279: 34279.3.patch

File 34279.3.patch, 3.6 KB (added by pbearne, 9 years ago)

I updated devop to the latest version and re made the patch so I hope it patch OK now

  • src/wp-includes/formatting.php

     
    611611                        . ')*+'         // Loop possessively.
    612612                        . '(?:]]>)?';   // End of comment. If not found, match all input.
    613613
    614                 $escaped = 
     614                $escaped =
    615615                          '(?='           // Is the element escaped?
    616616                        .    '!--'
    617617                        . '|'
     
    25602560        return chr( hexdec( strtolower( $match[1] ) ) );
    25612561}
    25622562
     2563
    25632564/**
    25642565 * Returns a date in the GMT equivalent.
    25652566 *
     
    25722573 *
    25732574 * @param string $string The date to be converted.
    25742575 * @param string $format The format string for the returned date (default is Y-m-d H:i:s)
     2576 *
    25752577 * @return string GMT version of the date provided.
    25762578 */
    25772579function get_gmt_from_date( $string, $format = 'Y-m-d H:i:s' ) {
     
    25782580        $tz = get_option( 'timezone_string' );
    25792581        if ( $tz ) {
    25802582                $datetime = date_create( $string, new DateTimeZone( $tz ) );
    2581                 if ( ! $datetime )
     2583                if ( ! $datetime ) {
    25822584                        return gmdate( $format, 0 );
     2585                }
    25832586                $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
    25842587                $string_gmt = $datetime->format( $format );
    25852588        } else {
    2586                 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 ) )
    2587                         return gmdate( $format, 0 );
     2589                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 ) ) {
     2590                        $datetime = strtotime( $string );
     2591                        if ( false === $datetime ) {
     2592                                return gmdate( $format, 0 );
     2593                        }
     2594
     2595                        return gmdate( $format, $datetime );
     2596                }
    25882597                $string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] );
    2589                 $string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
     2598                $string_gmt  = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
    25902599        }
     2600
    25912601        return $string_gmt;
    25922602}
    25932603
  • tests/phpunit/tests/formatting/date.php

     
    4444        function test_get_gmt_from_date_during_dst() {
    4545                update_option( 'timezone_string', 'Europe/London' );
    4646                $local = '2012-06-01 12:34:56';
    47                 $gmt = '2012-06-01 11:34:56';
     47                $gmt   = '2012-06-01 11:34:56';
    4848                $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
    4949        }
     50
     51        /**
     52         * @ticket 34279
     53         */
     54        function test_get_date_and_time_from_gmt_no_timezone() {
     55                $gmt = $local = '2012-01-01 12:34:56';
     56                $this->assertEquals( $gmt, get_date_from_gmt( $local ) );
     57        }
     58
     59        /**
     60         * @ticket 34279
     61         */
     62        function test_get_gmt_from_date_no_timezone() {
     63                $gmt  = '2012-12-01 00:00:00';
     64                $date = '2012-12-01';
     65                $this->assertEquals( $gmt, get_gmt_from_date( $date ) );
     66        }
     67
     68
     69        /**
     70         *
     71         * @ticket 34279
     72         */
     73        function test_get_gmt_from_date_short_date() {
     74                update_option( 'timezone_string', 'Europe/London' );
     75                $local = '2012-12-01';
     76                $gmt = '2012-12-01 00:00:00';
     77                $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
     78        }
     79
     80        /**
     81         *
     82         * @ticket 34279
     83         */
     84        function test_get_gmt_from_date_string_date() {
     85                update_option( 'timezone_string', 'Europe/London' );
     86                $local = 'now';
     87                $gmt = gmdate( 'Y-m-d H:i:s', strtotime( 'now' ) );
     88                $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
     89        }
     90
     91        /**
     92        *
     93        * @ticket 34279
     94        */
     95        function test_get_gmt_from_date_string_date_no_timezone() {
     96                $local = 'now';
     97                $gmt = gmdate( 'Y-m-d H:i:s', strtotime( 'now' ) );
     98                $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
     99        }
    50100}