[wp-trac] [WordPress Trac] #41782: Using date_query with 'before' in WP_Query returns wrong timezone

WordPress Trac noreply at wordpress.org
Thu Aug 22 03:00:42 UTC 2019


#41782: Using date_query with 'before' in WP_Query returns wrong timezone
--------------------------------------+-----------------------------
 Reporter:  Biranit                   |       Owner:  SergeyBiryukov
     Type:  defect (bug)              |      Status:  reviewing
 Priority:  normal                    |   Milestone:  5.3
Component:  Date/Time                 |     Version:  4.8.1
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------------

Comment (by SergeyBiryukov):

 Replying to [comment:11 Rarst]:
 > I couldn't reproduce timezone shift as described, but there are
 ''definitely'' time zone issues in there.
 >
 > Attached a patch that improves unit tests coverage for different cases
 and handling of arbitrary input.

 Thanks for the patch!

 I couldn't get `phpunit --group date` to pass with [attachment:"build-
 mysql-datetime1.patch"]:
 {{{
 There were 2 failures:

 1) Tests_Date_I18n::test_should_format_date
 The dates should be equal
 Failed asserting that 1566453248 matches expected 1566442448.

 S:\home\wordpress.test\develop\tests\phpunit\tests\date\dateI18n.php:9

 2) Tests_WP_Date_Query::test_build_mysql_datetime with data set #0 ('-1
 day', '2019-08-21 05:53:57')
 Expected 2019-08-21 05:53:57, got 2019-08-21 05:54:11
 Failed asserting that 1566366851 matches expected 1566366837.

 S:\home\wordpress.test\develop\tests\phpunit\tests\date\query.php:526
 }}}

 Apparently setting `timezone_string` in a data provider doesn't work as
 expected: it affects other tests and happens far before the test is
 actually executed, so the minutes and seconds don't match.

 Splitting the tests into several groups in [attachment:41782.diff]
 (general, custom timezone, relative date) seems to work.

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


More information about the wp-trac mailing list