Ensure that WP_Date_Query
accepts a value of 0
for 'hour'.
Props jim912. Fixes #34228. git-svn-id: https://develop.svn.wordpress.org/trunk@34989 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
eeea5d753a
commit
dc2b7c634d
@ -992,7 +992,7 @@ class WP_Date_Query {
|
||||
$format = $time = '';
|
||||
|
||||
// Hour
|
||||
if ( $hour ) {
|
||||
if ( null !== $hour ) {
|
||||
$format .= '%H.';
|
||||
$time .= sprintf( '%02d', $hour ) . '.';
|
||||
} else {
|
||||
|
@ -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() );
|
||||
|
||||
|
@ -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', ) );
|
||||
|
Loading…
Reference in New Issue
Block a user