WP_Date_Query
date validation should not fail for hour = 0.
Props ChriCo, tyxla. Fixes #31067 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@31251 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
37ea642f69
commit
f1771073dc
@ -368,7 +368,7 @@ class WP_Date_Query {
|
|||||||
|
|
||||||
// Hours per day.
|
// Hours per day.
|
||||||
$min_max_checks['hour'] = array(
|
$min_max_checks['hour'] = array(
|
||||||
'min' => 1,
|
'min' => 0,
|
||||||
'max' => 23
|
'max' => 23
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -394,7 +394,7 @@ class WP_Date_Query {
|
|||||||
foreach ( (array) $date_query[ $key ] as $_value ) {
|
foreach ( (array) $date_query[ $key ] as $_value ) {
|
||||||
$is_between = $_value >= $check['min'] && $_value <= $check['max'];
|
$is_between = $_value >= $check['min'] && $_value <= $check['max'];
|
||||||
|
|
||||||
if ( ! $is_between ) {
|
if ( ! is_numeric( $_value ) || ! $is_between ) {
|
||||||
$error = sprintf(
|
$error = sprintf(
|
||||||
/* translators: Date query invalid date message: 1: invalid value, 2: type of value, 3: minimum valid value, 4: maximum valid value */
|
/* translators: Date query invalid date message: 1: invalid value, 2: type of value, 3: minimum valid value, 4: maximum valid value */
|
||||||
__( 'Invalid value %1$s for %2$s. Expected value should be between %3$s and %4$s.' ),
|
__( 'Invalid value %1$s for %2$s. Expected value should be between %3$s and %4$s.' ),
|
||||||
|
@ -857,13 +857,13 @@ class Tests_WP_Date_Query extends WP_UnitTestCase {
|
|||||||
*/
|
*/
|
||||||
public function test_validate_date_values_hour() {
|
public function test_validate_date_values_hour() {
|
||||||
// Valid values.
|
// Valid values.
|
||||||
$hours = range( 1, 23 );
|
$hours = range( 0, 23 );
|
||||||
foreach ( $hours as $hour ) {
|
foreach ( $hours as $hour ) {
|
||||||
$this->assertTrue( $this->q->validate_date_values( array( 'hour' => $hour ) ) );
|
$this->assertTrue( $this->q->validate_date_values( array( 'hour' => $hour ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invalid values.
|
// Invalid values.
|
||||||
$hours = array( -1, 24, 25, 'string who wants to be a int' );
|
$hours = array( -1, 24, 25, 'string' );
|
||||||
foreach ( $hours as $hour ) {
|
foreach ( $hours as $hour ) {
|
||||||
$this->assertFalse( $this->q->validate_date_values( array( 'hour' => $hour ) ) );
|
$this->assertFalse( $this->q->validate_date_values( array( 'hour' => $hour ) ) );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user