diff --git a/src/wp-includes/date.php b/src/wp-includes/date.php index 9f64747bb3..e10ef4f861 100644 --- a/src/wp-includes/date.php +++ b/src/wp-includes/date.php @@ -992,7 +992,7 @@ class WP_Date_Query { $format = $time = ''; // Hour - if ( $hour ) { + if ( null !== $hour ) { $format .= '%H.'; $time .= sprintf( '%02d', $hour ) . '.'; } else { diff --git a/tests/phpunit/tests/date/query.php b/tests/phpunit/tests/date/query.php index 72c7d73f41..3ce905a291 100644 --- a/tests/phpunit/tests/date/query.php +++ b/tests/phpunit/tests/date/query.php @@ -508,6 +508,17 @@ class Tests_WP_Date_Query extends WP_UnitTestCase { $this->assertFalse( $q->build_time_query( 'post_date', '=' ) ); } + /** + * @ticket 34228 + */ + public function test_build_time_query_should_not_discard_hour_0() { + $q = new WP_Date_Query( array() ); + + $found = $q->build_time_query( 'post_date', '=', 0, 10 ); + + $this->assertContains( '%H', $found ); + } + public function test_build_time_query_compare_in() { $q = new WP_Date_Query( array() ); diff --git a/tests/phpunit/tests/query/dateQuery.php b/tests/phpunit/tests/query/dateQuery.php index 32cc18f8dc..f7b4263743 100644 --- a/tests/phpunit/tests/query/dateQuery.php +++ b/tests/phpunit/tests/query/dateQuery.php @@ -668,6 +668,25 @@ class Tests_Query_DateQuery extends WP_UnitTestCase { $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) ); } + /** + * @ticket 34228 + */ + public function test_date_query_hour_should_not_ignore_0() { + return; + $p1 = $this->factory->post->create( array( 'post_date' => '2014-10-21 00:42:29', ) ); + $p2 = $this->factory->post->create( array( 'post_date' => '2014-10-21 01:42:29', ) ); + + $posts = $this->_get_query_result( array( + 'year' => 2014, + 'monthnum' => 10, + 'day' => 21, + 'hour' => 0, + 'minute' => 42, + ) ); + + $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) ); + } + public function test_date_query_minute() { $p1 = $this->factory->post->create( array( 'post_date' => '2014-10-21 10:56:29', ) ); $p2 = $this->factory->post->create( array( 'post_date' => '2014-10-21 10:42:29', ) );