Make WordPress Core

Changeset 34989


Ignore:
Timestamp:
10/09/2015 04:32:59 PM (11 years ago)
Author:
boonebgorges
Message:

Ensure that WP_Date_Query accepts a value of 0 for 'hour'.

Props jim912.
Fixes #34228.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/date.php

    r33803 r34989  
    993993
    994994                // Hour
    995                 if ( $hour ) {
     995                if ( null !== $hour ) {
    996996                        $format .= '%H.';
    997997                        $time   .= sprintf( '%02d', $hour ) . '.';
  • trunk/tests/phpunit/tests/date/query.php

    r31251 r34989  
    509509        }
    510510
     511        /**
     512         * @ticket 34228
     513         */
     514        public function test_build_time_query_should_not_discard_hour_0() {
     515                $q = new WP_Date_Query( array() );
     516
     517                $found = $q->build_time_query( 'post_date', '=', 0, 10 );
     518
     519                $this->assertContains( '%H', $found );
     520        }
     521
    511522        public function test_build_time_query_compare_in() {
    512523                $q = new WP_Date_Query( array() );
  • trunk/tests/phpunit/tests/query/dateQuery.php

    r30142 r34989  
    664664                                ),
    665665                        ),
     666                ) );
     667
     668                $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     669        }
     670
     671        /**
     672         * @ticket 34228
     673         */
     674        public function test_date_query_hour_should_not_ignore_0() {
     675                return;
     676                $p1 = $this->factory->post->create( array( 'post_date' => '2014-10-21 00:42:29', ) );
     677                $p2 = $this->factory->post->create( array( 'post_date' => '2014-10-21 01:42:29', ) );
     678
     679                $posts = $this->_get_query_result( array(
     680                        'year' => 2014,
     681                        'monthnum' => 10,
     682                        'day' => 21,
     683                        'hour' => 0,
     684                        'minute' => 42,
    666685                ) );
    667686
Note: See TracChangeset for help on using the changeset viewer.