[wp-trac] [WordPress Trac] #26653: Date Query "inclusive" logic

WordPress Trac noreply at wordpress.org
Mon Dec 16 17:25:20 UTC 2013


#26653: Date Query "inclusive" logic
--------------------------+-----------------------------
 Reporter:  mboynes       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 When querying dates ranges using before and after, the date logic when
 `'inclusive' => true` seems non-intuitive. Consider the following date
 query:

 {{{
 $date_query = array(
         'after' => array( 'year' => 2013, 'month' => 1 ),
         'before' => array( 'year' => 2013, 'month' => 3 ),
         'inclusive' => true
 );)
 }}}

 I would expect this to search between 2013-01-01 00:00:00 and
 2013-03-31-23:59:59, but it actually generates the following SQL:

 {{{
 ( post_date >= '2013-01-31 23:59:59' AND post_date <= '2013-03-01
 00:00:00' )
 }}}
 "Inclusive" is essentially only including one second of the most refined
 argument you pass (here, that's month). The logic is perfect when
 "inclusive" is set to `false`. It seems to me that when `'inclusive' =>
 true`, the `$default_to_max` parameter passed to
 `WP_Date_Query::build_mysql_datetime()` should be inverted. Patch attached
 which does this.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/26653>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list