[wp-trac] [WordPress Trac] #31067: WP_Date_Query - broken hour-validation

WordPress Trac noreply at wordpress.org
Wed Jan 21 12:42:00 UTC 2015

#31067: WP_Date_Query - broken hour-validation
 Reporter:  ChriCo                        |       Owner:  boonebgorges
     Type:  defect (bug)                  |      Status:  reopened
 Priority:  normal                        |   Milestone:  4.1.1
Component:  Query                         |     Version:  4.1
 Severity:  normal                        |  Resolution:
 Keywords:  has-patch commit fixed-major  |     Focuses:

Comment (by ChriCo):

 > The one you linked to only checks the 'year'. Perhaps the 'year' one is
 no longer needed, but this needs testing.

 Yep you're right, so the year can be removed in my second link.

 > It seems a little bit verbose to have separate functions for all of this
 - it's not easy to see how they'd be used anywhere else in WordPress
 itself - but it might be worth considering having a single date validation
 function. If you think this is worth pursuing, please feel free to open an
 enhancement ticket.

 Yes and no. This "function" was a simple example for extracting the
 validation to a reusable component which can be tested with Unit Tests.
 The best thing would be a Validation-/Sanitizing-API which can be used in
 other situations too.

 The hour, day, month, ... is nothing else than a "is_between"-check:

 function is_between( $value, $args ) {

         $default_args = array(
                 'min'           => 0,
                 'max'           => PHP_INT_MAX,
                 'inclusive      => TRUE

         $args = wp_parse_args( $args, $default_args );

          if ( (bool) $args[ 'inclusive' ] ) {
                 if ( $args[ 'min' ] > $value || $value > $args[ 'max' ] )
                         return false;
         } else {
                 if ( $args[ 'min' ] >= $value || $value >= $args[ 'max' ]
 ) {
                         return false;

         return true;

 The current "validation"-implementation in WP_Date_Query is way to complex
 and are just special validations for date-queries.

Ticket URL: <https://core.trac.wordpress.org/ticket/31067#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list