Make WordPress Core

Ticket #34279: 34279.patch

File 34279.patch, 3.1 KB (added by pbearne, 10 years ago)

patch and unit tests

  • 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                        . '|'
     
    25782578        $tz = get_option( 'timezone_string' );
    25792579        if ( $tz ) {
    25802580                $datetime = date_create( $string, new DateTimeZone( $tz ) );
    2581                 if ( ! $datetime )
     2581                if ( ! $datetime ){
    25822582                        return gmdate( $format, 0 );
     2583                }
    25832584                $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
    25842585                $string_gmt = $datetime->format( $format );
    25852586        } 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 );
     2587                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 ) ){
     2588                        $datetime = strtotime( $string );
     2589                        if( false === $datetime ){
     2590                                return gmdate( $format, 0 );
     2591                        }
     2592                        return gmdate( $format, $datetime );
     2593                }
    25882594                $string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] );
    25892595                $string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
    25902596        }
  • 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                $local = '2012-12-01';
     64                $gmt = '2012-12-01 00:00:00';
     65                $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
     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}