diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-11-07 16:12:13 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-11-09 06:56:44 -0500 |
| commit | ca0278f49652c0069d82c08917e0c420dede207b (patch) | |
| tree | 2d834fbbc3cc3075a055271d39622d64734ea0a4 /tests/utils_tests/test_dateformat.py | |
| parent | f5e1d72de2e111ef2449f858b672c9cf4ecbb9ff (diff) | |
[1.9.x] Fixed debug view crash during autumn DST change.
This only happens if USE_TZ = False and pytz is installed (perhaps not
the most logical combination, but who am I to jugde?)
Refs #23714 which essentially fixed the same problem when USE_TZ = True.
Thanks Florian and Carl for insisting until I wrote a complete patch.
Backport of 1014ba026e879e56e0f265a8d9f54e6f39843348 from master
Diffstat (limited to 'tests/utils_tests/test_dateformat.py')
| -rw-r--r-- | tests/utils_tests/test_dateformat.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/utils_tests/test_dateformat.py b/tests/utils_tests/test_dateformat.py index faf4b6605b..918cc2a518 100644 --- a/tests/utils_tests/test_dateformat.py +++ b/tests/utils_tests/test_dateformat.py @@ -10,6 +10,11 @@ from django.utils.timezone import ( get_default_timezone, get_fixed_timezone, make_aware, utc, ) +try: + import pytz +except ImportError: + pytz = None + @override_settings(TIME_ZONE='Europe/Copenhagen') class DateFormatTests(SimpleTestCase): @@ -29,6 +34,18 @@ class DateFormatTests(SimpleTestCase): dt = datetime(2009, 5, 16, 5, 30, 30) self.assertEqual(datetime.fromtimestamp(int(format(dt, 'U'))), dt) + def test_naive_ambiguous_datetime(self): + # dt is ambiguous in Europe/Copenhagen. LocalTimezone guesses the + # offset (and gets it wrong 50% of the time) while pytz refuses the + # temptation to guess. In any case, this shouldn't crash. + dt = datetime(2015, 10, 25, 2, 30, 0) + + # Try all formatters that involve self.timezone. + self.assertEqual(format(dt, 'I'), '0' if pytz is None else '') + self.assertEqual(format(dt, 'O'), '+0100' if pytz is None else '') + self.assertEqual(format(dt, 'T'), 'CET' if pytz is None else '') + self.assertEqual(format(dt, 'Z'), '3600' if pytz is None else '') + @requires_tz_support def test_datetime_with_local_tzinfo(self): ltz = get_default_timezone() |
