diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 9d22905b8c..6ec16b72b0 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -1898,7 +1898,7 @@ function the_date_xml() { function the_date( $d = '', $before = '', $after = '', $echo = true ) { global $currentday, $previousday; - if ( $currentday != $previousday ) { + if ( is_new_day() ) { $the_date = $before . get_the_date( $d ) . $after; $previousday = $currentday; diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 69d9390edd..0966fa1ca1 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -671,4 +671,42 @@ class Tests_Functions extends WP_UnitTestCase { $json = wp_json_encode( $data, 0, 1 ); $this->assertFalse( $json ); } + + /** + * @ticket 33750 + */ + function test_the_date() { + ob_start(); + the_date(); + $actual = ob_get_clean(); + $this->assertEquals( '', $actual ); + + $GLOBALS['post'] = $this->factory->post->create_and_get( array( + 'post_date' => '2015-09-16 08:00:00' + ) ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date(); + $this->assertEquals( 'September 16, 2015', ob_get_clean() ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date( 'Y' ); + $this->assertEquals( '2015', ob_get_clean() ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date( 'Y', 'before ', ' after' ); + $this->assertEquals( 'before 2015 after', ob_get_clean() ); + + ob_start(); + $GLOBALS['currentday'] = '18.09.15'; + $GLOBALS['previousday'] = '17.09.15'; + the_date( 'Y', 'before ', ' after', false ); + $this->assertEquals( '', ob_get_clean() ); + } }