Problem/Motivation

Currently, tests/core/bootstrap.php sets the timezone to be UTC because (from core/tests/bootstrap.php):

// Set the default timezone. While this doesn't cause any tests to fail, PHP
// complains if 'date.timezone' is not set in php.ini.
date_default_timezone_set('UTC');

UTC is not a good choice because it may mask problems. We run TestBot outside of the root directory to make sure we don't have any code that accidentally relies on or only works when the base URL is /. Choosing a TZ at the far edge is similar. Dates in are stored as UTC in the database. By choosing something close to the extreme, you will expose bugs that assume UTC b/c you often have day rollover when the TZ is applied to the value pulled from the database. Thought would need to go into whether a large positive value or a large negative value make more sense for finding potential bugs.

Proposed resolution

Set a timezone near the extreme to catch edge cases, and then fix any tests that break.

Remaining tasks

Do it.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because we choose and change the default timezone used by unit tests, thus improving the test suite.
Issue priority Normal because there is nothing broken at the moment.
Unfrozen changes Unfrozen because it only changes tests, more specific it changes the default timezone that all unit tests use.
Prioritized changes While not in the list of prioritized changes, the purpose of this is to prevent TZ related regressions and reduce the fragility of the testing system in general, where there are cases when tests pass or fail depending on when they run of where they run (TestBot vs Local).
Disruption None
CommentFileSizeAuthor
#38 unit_tests_should_use_a-2498619-38.patch1.5 KBAnonymous (not verified)
#38 interdiff-35-38.txt759 bytesAnonymous (not verified)
#35 unit_tests_should_use_a-2498619-35.patch1.18 KBAnonymous (not verified)
#32 unit_tests_should_use_a-2498619-32.patch1.19 KBAnonymous (not verified)
#28 DE_2498619.patch473 bytesAnonymous (not verified)
#28 LA_2498619.patch478 bytesAnonymous (not verified)
#17 plus14-2498619-17.patch477 bytesAnonymous (not verified)
#17 plus13-2498619-17.patch476 bytesAnonymous (not verified)
#17 plus1245-2498619-17.patch474 bytesAnonymous (not verified)
#17 plus12-2498619-17.patch475 bytesAnonymous (not verified)
#17 plus1130-2498619-17.patch474 bytesAnonymous (not verified)
#17 plus11-2498619-17.patch471 bytesAnonymous (not verified)
#17 min11-2498619-17.patch473 bytesAnonymous (not verified)
#5 unit_tests_should_use_a-2498619-5.patch1.17 KBAnonymous (not verified)
#5 unit_tests_should_use_a-2498619-5-test-fail.patch469 bytesAnonymous (not verified)
#1 unit_tests_should_use_a-2498619-test-only.patch469 bytesmpdonadio
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpdonadio’s picture

Status: Active » Needs review
FileSize
469 bytes

I think the only failure will be in \Drupal\Tests\Core\Datetime\DateTest

Status: Needs review » Needs work

The last submitted patch, 1: unit_tests_should_use_a-2498619-test-only.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: unit_tests_should_use_a-2498619-test-only.patch, failed testing.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
469 bytes
1.17 KB

Thought would need to go into whether a large positive value or a large negative value make more sense for finding potential bugs.

The list of timezones is finite: http://us.php.net/manual/en/timezones.php

The db that is used can be consulted in PECL's » timezonedb, so I downloaded that and it has a header file where all possibilities are listed. There, you can see the exact values.

{ "Africa/Abidjan"                    , 0x000000 },
{ "Africa/Accra"                      , 0x0000B6 },
...
{ "Asia/Tokyo"                        , 0x0520C2 },
...
{ "UTC"                               , 0x0A9120 },
{ "W-SU"                              , 0x0A9908 },
{ "WET"                               , 0x0A91AB },
{ "Zulu"                              , 0x0A9F0C },

These are values between 0 and 696076, so we definitely don't want to choose a negative value.

Then, looking at http://us.php.net/manual/en/timezones.others.php we can see that some timezones only are listed for backwards compatibility but shouldn't be used (e.g. WET and ZULU).

In conclusion, "Asia/Tokyo" as proposed in #1 is as good as any. And choosing something far away from the default UTC seems the sane thing to do. So let's keep that.

mpdonadio’s picture

I'm not sure if those numbers really correspond to anything related to the offset. UTC, WET, Zulu, and GMT are all essentially the same thing (though WET would also include DST whenever that happens, and UTC and GMT are technically different but equivalent for most practical purposes as far as computers are concerned), but they all have different numbers in that header. I think they are indexes into the "database" that is in that header after the list of zones.

Anonymous’s picture

Yes, but that would be the number that is internally used by PECL? I think I've misunderstood the thing to research completely...

Judging from "related to the offset", did you mean something more like:

If we look at a list of timezones, and we find:

'Asia/Tokyo' => "(GMT+09:00) Tokyo",

Then the question is whether or not we want to use something more "edge case like", e.g.:

'Pacific/Midway' => "(GMT-11:00) Midway Island",
or
'Pacific/Fiji' => "(GMT+12:00) Fiji",

In that case I'm not sure if it would make a big difference in finding bugs, but it couldn't harm us to choose Pacific/Kiritimati (UTC+14:00). They are the first to reach a new day.

Fwiw, on the other far edge we have UTC-12:00, which (TIL) apparently is only used by ships.

The last submitted patch, 5: unit_tests_should_use_a-2498619-5-test-fail.patch, failed testing.

The last submitted patch, 5: unit_tests_should_use_a-2498619-5-test-fail.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: unit_tests_should_use_a-2498619-5.patch, failed testing.

Status: Needs work » Needs review

The last submitted patch, 1: unit_tests_should_use_a-2498619-test-only.patch, failed testing.

The last submitted patch, 5: unit_tests_should_use_a-2498619-5-test-fail.patch, failed testing.

mpdonadio’s picture

Yeah, I was talking about picking something closer to the international date line. We should probably run some tests to see what happens at UTC-11, UTC-12, UTC+11, UTC+12, UTC+13, and UTC+14. I honestly don't know what +-12, +13 and +14 will do; they are kinda super edge cases.

Anonymous’s picture

Ok, so here goes:

UTC-12: seems not to have a readable alias
UTC-11: Pacific/Midway

UTC+11: Asia/Magadan
UTC+11:30: Pacific/Norfolk
UTC+12: Pacific/Auckland
UTC+12:45: Pacific/Chatham
UTC+13: Pacific/Tongatapu
UTC+14: Pacific/Kiritimati

The last submitted patch, 17: min11-2498619-17.patch, failed testing.

The last submitted patch, 17: plus11-2498619-17.patch, failed testing.

The last submitted patch, 17: plus1130-2498619-17.patch, failed testing.

The last submitted patch, 17: plus12-2498619-17.patch, failed testing.

The last submitted patch, 17: plus1245-2498619-17.patch, failed testing.

The last submitted patch, 17: plus13-2498619-17.patch, failed testing.

Anonymous’s picture

Status: Needs review » Needs work

Well, that's an interesting result.

The "extra fails" for Asia/Magadan are:

('10 years', 1071097748, 1386713348) Exception: Expected: 10 years | Diff: 9 years 11 months
('100 years', -1769039644, 1386713348) Exception: Expected: 100 years | Diff: 99 years 11 months

The other "extra fails" are similar.

It seems like the one we are looking for is "Asia/Magada" then?

The last submitted patch, 17: plus14-2498619-17.patch, failed testing.

mpdonadio’s picture

Thanks for doing those.

These are some odd results. I wonder if DST was also in play for those? Need to mull this one over and do some reading.

Anonymous’s picture

None of these timezones use DST, however all of them experimented with the concept. Based on the info on timezoneconvertor.com and wikipedia.org, it seems that these changes at least correlate with the extra failures.

UTC-11: Pacific/Midway: DST ended on Wed 30-Nov-1983 with no actual change change -> no extra failure
UTC+11: Asia/Magadan: Moscow+08 (Moscow+07 after 2014-10-26) -> failure for 10 years and 100 years
UTC+11:30: Pacific/Norfolk: DST ended on Mon 1-Jan-1951, 18 minutes forward-> failure for 100 years
UTC+12: Pacific/Auckland: DST ended on Sun 5-Apr-2015, backward 1 hour -> no extra failure
UTC+12:45: Pacific/Chatham: DST ended on Sun 5-Apr-2015, backward 1 hour -> no extra failure
UTC+13: Pacific/Tongatapu: DST ended on Sun 27-Jan-2002, 1 hour backwards -> failure for 100 years
UTC+14: Pacific/Kiritimati: DST ended on Sun 1-Jan-1995 with no actual change -> failure for 100 years

I can reproduce these failures on my local machine. According to phpinfo(), it uses the system timezone information (so not the pecl timezonedb). If my timezone database version was build between 10/2014 and 04/2015 (not sure how to check), then the extra failures seem to be caused by these jumps in time.

So to get back to the question at hand, if we want edge case we could pick one with historical changes in DST and fix the test accordingly. However, I don't think fixing the failures would look very logical. Someone just browsing the test would definitely not get that. That makes me lean towards using "Pacific/Midway".

Note that all this commotion is caused by a single function call. Do we have use cases other than diff()?

As for the diff() function itself, we could also look to a timezone that uses DST? If we do that, we should expand the test coverage in datetest, to test all months in a certain year. We don't have that now.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
478 bytes
473 bytes

These are two examples that have DST:
- America/Los_Angeles: −08:00 (DST is −07:00)
- America/Denver: −07:00 (DST is −06:00)

The last submitted patch, 28: LA_2498619.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 28: DE_2498619.patch, failed testing.

mpdonadio’s picture

Anonymous’s picture

Status: Needs work » Needs review
FileSize
1.19 KB

I don't think we want a super edge case, so I'd say we pick one with DST.

Anonymous’s picture

Issue summary: View changes

Added beta eval.

mpdonadio’s picture

Issue summary: View changes

Lets go with something a little more extreme. I think Australia/Sydney would be good. UTC+10 and it participates in DST.

Anonymous’s picture

mpdonadio’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good, ran locally w/o any fails. IS and Beta Eval are updated and reflect why this change would be good for 8.0.x. This is good to go from my perspective.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/bootstrap.php
@@ -88,4 +88,4 @@ function drupal_phpunit_register_extension_dirs(Composer\Autoload\ClassLoader $l
 // Set the default timezone. While this doesn't cause any tests to fail, PHP
 // complains if 'date.timezone' is not set in php.ini.
-date_default_timezone_set('UTC');
+date_default_timezone_set('Australia/Sydney');

If we're going to do this then we need a comment to explain why Australia/Sydney.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
759 bytes
1.5 KB

Fair enough. How about we borrow some text from the IS?

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

I was asked to take a look at the docs in the interdiff here. They look fine to me. Since that was the only reason the patch was set to Needs Work above, back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed ef105e7 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

  • alexpott committed ef105e7 on 8.0.x
    Issue #2498619 by pjonckiere, mpdonadio: Unit tests should use a default...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.