Make WordPress Core


Ignore:
Timestamp:
10/20/2015 06:07:45 AM (11 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/tests/phpunit/tests/formatting/date.php

    r25002 r35284  
    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         * @ticket 34279
     70         */
     71        function test_get_gmt_from_date_short_date() {
     72                update_option( 'timezone_string', 'Europe/London' );
     73                $local = '2012-12-01';
     74                $gmt = '2012-12-01 00:00:00';
     75                $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
     76        }
     77
     78        /**
     79         * @ticket 34279
     80         */
     81        function test_get_gmt_from_date_string_date() {
     82                update_option( 'timezone_string', 'Europe/London' );
     83                $local = 'now';
     84                $gmt = gmdate( 'Y-m-d H:i:s', strtotime( 'now' ) );
     85                $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
     86        }
     87
     88        /**
     89         * @ticket 34279
     90         */
     91        function test_get_gmt_from_date_string_date_no_timezone() {
     92                $local = 'now';
     93                $gmt = gmdate( 'Y-m-d H:i:s', strtotime( 'now' ) );
     94                $this->assertEquals( $gmt, get_gmt_from_date( $local ) );
     95        }
    5096}
Note: See TracChangeset for help on using the changeset viewer.