Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit f830166167833cfb7c990764f72373a9f4494259 1 parent 38999f7
Aymeric Augustin authored October 13, 2011
4  django/utils/tzinfo.py
@@ -57,7 +57,9 @@ def tzname(self, dt):
57 57
             return None
58 58
 
59 59
     def _isdst(self, dt):
60  
-        tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
  60
+        tt = (dt.year, dt.month, dt.day,
  61
+              dt.hour, dt.minute, dt.second,
  62
+              dt.weekday(), 0, 0)
61 63
         try:
62 64
             stamp = time.mktime(tt)
63 65
         except (OverflowError, ValueError):
50  tests/regressiontests/utils/tzinfo.py
... ...
@@ -1,9 +1,35 @@
1  
-import unittest
2  
-
3  
-from django.utils.tzinfo import FixedOffset
  1
+import datetime
  2
+import os
  3
+import time
  4
+from django.utils.tzinfo import FixedOffset, LocalTimezone
  5
+from django.utils import unittest
4 6
 
5 7
 class TzinfoTests(unittest.TestCase):
6 8
 
  9
+    @classmethod
  10
+    def setUpClass(cls):
  11
+        cls.old_TZ = os.environ.get('TZ')
  12
+        os.environ['TZ'] = 'US/Eastern'
  13
+
  14
+        try:
  15
+            # Check if a timezone has been set
  16
+            time.tzset()
  17
+            cls.tz_tests = True
  18
+        except AttributeError:
  19
+            # No timezone available. Don't run the tests that require a TZ
  20
+            cls.tz_tests = False
  21
+
  22
+    @classmethod
  23
+    def tearDownClass(cls):
  24
+        if cls.old_TZ is None:
  25
+            del os.environ['TZ']
  26
+        else:
  27
+            os.environ['TZ'] = cls.old_TZ
  28
+
  29
+        # Cleanup - force re-evaluation of TZ environment variable.
  30
+        if cls.tz_tests:
  31
+            time.tzset()
  32
+
7 33
     def test_fixedoffset(self):
8 34
         self.assertEqual(repr(FixedOffset(0)), '+0000')
9 35
         self.assertEqual(repr(FixedOffset(60)), '+0100')
@@ -16,3 +42,21 @@ def test_fixedoffset(self):
16 42
         self.assertEqual(repr(FixedOffset(5.5*60)), '+0530')
17 43
         self.assertEqual(repr(FixedOffset(-.5*60)), '-0030')
18 44
         self.assertEqual(repr(FixedOffset(.5*60)), '+0030')
  45
+
  46
+    def test_16899(self):
  47
+        if not self.tz_tests:
  48
+            return
  49
+        ts = 1289106000
  50
+        # Midnight at the end of DST in US/Eastern: 2010-11-07T05:00:00Z
  51
+        dt = datetime.datetime.utcfromtimestamp(ts)
  52
+        # US/Eastern -- we force its representation to "EST"
  53
+        tz = LocalTimezone(dt + datetime.timedelta(days=1))
  54
+        self.assertEqual(
  55
+                repr(datetime.datetime.fromtimestamp(ts - 3600, tz)),
  56
+                'datetime.datetime(2010, 11, 7, 0, 0, tzinfo=EST)')
  57
+        self.assertEqual(
  58
+                repr(datetime.datetime.fromtimestamp(ts, tz)),
  59
+                'datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST)')
  60
+        self.assertEqual(
  61
+                repr(datetime.datetime.fromtimestamp(ts + 3600, tz)),
  62
+                'datetime.datetime(2010, 11, 7, 1, 0, tzinfo=EST)')

0 notes on commit f830166

Please sign in to comment.
Something went wrong with that request. Please try again.