[wp-trac] [WordPress Trac] #29908: date_query inclusive logic still not quite right

WordPress Trac noreply at wordpress.org
Mon Oct 13 01:52:54 UTC 2014


#29908: date_query inclusive logic still not quite right
-------------------------------------+---------------------------
 Reporter:  magicroundabout          |       Owner:  boonebgorges
     Type:  defect (bug)             |      Status:  accepted
 Priority:  normal                   |   Milestone:  4.1
Component:  Query                    |     Version:  4.0
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+---------------------------
Changes (by boonebgorges):

 * keywords:  needs-patch => has-patch needs-testing
 * owner:   => boonebgorges
 * status:  new => accepted
 * milestone:  Future Release => 4.1


Comment:

 Replying to [comment:3 nacin]:
 > It would probably be easier if it generated this instead:
 > {{{
 > AND ( ( post_date >= '2013-04-07 00:00:00'
 > AND post_date < '2013-10-14 00:00:00' ) )
 > }}}

 If I were building this from scratch, I might agree with you. But the
 rounding-up logic is already in WP_Date_Query, for when an incomplete
 array value like `array( 'year' => 2013, 'month' => 04 )` is passed. So it
 makes sense to use it.

 The real challenge here is figuring out what date formats to accept.
 [29908.patch] adds inclusive support for `Y`, `Y-m`, `Y-m-d`, `Y-m-d H:i`,
 and `Y-m-d H:i:s`, as well as the same formats with `/` instead of `-`.
 (If there is PHP tool for computing the date format from a string -
 _without_ rounding it down, like `strtotime()` - I couldn't find it.
 Obviously they have the internals....) I figure this is better than
 nothing, and the first three in particular will probably cover many use
 cases.

 magicroundabout, you want to have a look and see if it's working for you?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29908#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list