Make WordPress Core


Ignore:
Timestamp:
08/31/2020 03:56:41 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Make sure get_the_date() and related functions return correct time if the format was specified as false.

Technically, the $format argument should always be a string, but passing false used to work before [47808], so this restores backward compatibility.

The list of affected functions:

  • get_the_date()
  • get_the_time()
  • get_comment_date()
  • get_comment_time()

Props wittich, Rarst, akabarikalpesh, SergeyBiryukov.
Fixes #51184.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/date/getTheDate.php

    r48911 r48912  
    1111         * @ticket 13771
    1212         */
    13         function test_get_the_date_with_id_returns_correct_time() {
     13        function test_get_the_date_returns_correct_time_with_post_id() {
    1414                $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) );
     15
    1516                $this->assertEquals( 'March 1, 2014', get_the_date( 'F j, Y', $post_id ) );
    1617        }
     
    2728
    2829        /**
     30         * @ticket 51184
     31         */
     32        function test_get_the_date_returns_correct_time_with_empty_format() {
     33                $post_id = self::factory()->post->create( array( 'post_date' => '2020-08-29 01:51:00' ) );
     34
     35                $this->assertEquals( 'August 29, 2020', get_the_date( '', $post_id ) );
     36                $this->assertEquals( 'August 29, 2020', get_the_date( false, $post_id ) );
     37        }
     38
     39        /**
    2940         * @ticket 28310
    3041         */
    31         function test_get_the_time_with_id_returns_correct_time() {
     42        function test_get_the_time_returns_correct_time_with_post_id() {
    3243                $post_id = self::factory()->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) );
     44
    3345                $this->assertEquals( '16:35:00', get_the_time( 'H:i:s', $post_id ) );
    3446        }
     
    4355                $this->assertFalse( get_the_time( 'h:i:s', 9 ) );
    4456        }
     57
     58        /**
     59         * @ticket 51184
     60         */
     61        function test_get_the_time_returns_correct_time_with_empty_format() {
     62                $post_id = self::factory()->post->create( array( 'post_date' => '2020-08-29 01:51:00' ) );
     63
     64                $this->assertEquals( '1:51 am', get_the_time( '', $post_id ) );
     65                $this->assertEquals( '1:51 am', get_the_time( false, $post_id ) );
     66        }
    4567}
Note: See TracChangeset for help on using the changeset viewer.