Make WordPress Core

Ticket #26653: 26653.diff

File 26653.diff, 2.4 KB (added by DrewAPicture, 11 years ago)

+ docs

  • src/wp-includes/date.php

     
    4848        /**
    4949         * Constructor.
    5050         *
     51         * @since 3.7.0
     52         * @since 4.0.0 The $inclusive logic was updated to include all times within the date range.
     53         *
    5154         * @param array $date_query {
    5255         *     One or more associative arrays of date query parameters.
    5356         *
     
    235238
    236239                $compare = $this->get_compare( $query );
    237240
     241                $inclusive = ! empty( $query['inclusive'] );
     242
     243                // Assign greater- and less-than values.
    238244                $lt = '<';
    239245                $gt = '>';
    240                 if ( ! empty( $query['inclusive'] ) ) {
     246
     247                if ( $inclusive ) {
    241248                        $lt .= '=';
    242249                        $gt .= '=';
    243250                }
    244251
    245252                // Range queries
    246253                if ( ! empty( $query['after'] ) )
    247                         $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], true ) );
     254                        $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );
    248255
    249256                if ( ! empty( $query['before'] ) )
    250                         $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], false ) );
     257                        $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
    251258
    252259                // Specific value queries
    253260
  • tests/phpunit/tests/query/dateQuery.php

     
    254254                $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    255255        }
    256256
     257        public function test_date_query_inclusive_between_dates() {
     258                $posts = $this->_get_query_result( array(
     259                        'date_query' => array(
     260                                'after' => array(
     261                                        'year' => 2007,
     262                                        'month' => 1
     263                                ),
     264                                'before' => array(
     265                                        'year' => 2008,
     266                                        'month' => 12
     267                                ),
     268                                'inclusive' => true
     269                        ),
     270                ) );
     271
     272
     273                $expected_dates = array(
     274                        '2007-01-22 03:49:21',
     275                        '2007-05-16 17:32:22',
     276                        '2007-09-24 07:17:23',
     277                        '2008-03-29 09:04:25',
     278                        '2008-07-15 11:32:26',
     279                        '2008-12-10 13:06:27',
     280                );
     281
     282                $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     283        }
     284
    257285        public function test_date_query_year_expecting_results() {
    258286                $posts = $this->_get_query_result( array(
    259287                        'date_query' => array(