summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2011-10-13 21:19:48 +0000
committerAymeric Augustin <aymeric.augustin@m4x.org>2011-10-13 21:19:48 +0000
commitf830166167833cfb7c990764f72373a9f4494259 (patch)
tree542c3f410e394bea6488b599d5f4a2d46239a14b
parent38999f7e00c15b27c8200e799d7f0f3e9af607bb (diff)
Fixed #16899 -- Backported the fix for http://bugs.python.org/issue9063 and added a test.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16980 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/utils/tzinfo.py4
-rw-r--r--tests/regressiontests/utils/tzinfo.py50
2 files changed, 50 insertions, 4 deletions
diff --git a/django/utils/tzinfo.py b/django/utils/tzinfo.py
index 7ba3673df4..daffffb496 100644
--- a/django/utils/tzinfo.py
+++ b/django/utils/tzinfo.py
@@ -57,7 +57,9 @@ class LocalTimezone(tzinfo):
return None
def _isdst(self, dt):
- tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
+ tt = (dt.year, dt.month, dt.day,
+ dt.hour, dt.minute, dt.second,
+ dt.weekday(), 0, 0)
try:
stamp = time.mktime(tt)
except (OverflowError, ValueError):
diff --git a/tests/regressiontests/utils/tzinfo.py b/tests/regressiontests/utils/tzinfo.py
index f2bc0b219a..a60a4574de 100644
--- a/tests/regressiontests/utils/tzinfo.py
+++ b/tests/regressiontests/utils/tzinfo.py
@@ -1,9 +1,35 @@
-import unittest
-
-from django.utils.tzinfo import FixedOffset
+import datetime
+import os
+import time
+from django.utils.tzinfo import FixedOffset, LocalTimezone
+from django.utils import unittest
class TzinfoTests(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ cls.old_TZ = os.environ.get('TZ')
+ os.environ['TZ'] = 'US/Eastern'
+
+ try:
+ # Check if a timezone has been set
+ time.tzset()
+ cls.tz_tests = True
+ except AttributeError:
+ # No timezone available. Don't run the tests that require a TZ
+ cls.tz_tests = False
+
+ @classmethod
+ def tearDownClass(cls):
+ if cls.old_TZ is None:
+ del os.environ['TZ']
+ else:
+ os.environ['TZ'] = cls.old_TZ
+
+ # Cleanup - force re-evaluation of TZ environment variable.
+ if cls.tz_tests:
+ time.tzset()
+
def test_fixedoffset(self):
self.assertEqual(repr(FixedOffset(0)), '+0000')
self.assertEqual(repr(FixedOffset(60)), '+0100')
@@ -16,3 +42,21 @@ class TzinfoTests(unittest.TestCase):
self.assertEqual(repr(FixedOffset(5.5*60)), '+0530')
self.assertEqual(repr(FixedOffset(-.5*60)), '-0030')
self.assertEqual(repr(FixedOffset(.5*60)), '+0030')
+
+ def test_16899(self):
+ if not self.tz_tests:
+ return
+ ts = 1289106000
+ # Midnight at the end of DST in US/Eastern: 2010-11-07T05:00:00Z
+ dt = datetime.datetime.utcfromtimestamp(ts)
+ # US/Eastern -- we force its representation to "EST"
+ tz = LocalTimezone(dt + datetime.timedelta(days=1))
+ self.assertEqual(
+ repr(datetime.datetime.fromtimestamp(ts - 3600, tz)),
+ 'datetime.datetime(2010, 11, 7, 0, 0, tzinfo=EST)')
+ self.assertEqual(
+ repr(datetime.datetime.fromtimestamp(ts, tz)),
+ 'datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST)')
+ self.assertEqual(
+ repr(datetime.datetime.fromtimestamp(ts + 3600, tz)),
+ 'datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST)')