Commits

Remy Blank committed 18bbd03

0.11.6dev: Fixed incorrect changes from [8831].

Re-closes #8240.

Comments (0)

Files changed (2)

 
     Any other input will trigger a `TypeError`.
     """
-    tzinfo = tzinfo or localtz
     if t is None:
-        return tzinfo.localize(datetime.now())
+        return datetime.now(tzinfo or localtz)
     elif isinstance(t, datetime):
         return t
     elif isinstance(t, date):
-        return tzinfo.localize(datetime(t.year, t.month, t.day))
+        return (tzinfo or localtz).localize(datetime(t.year, t.month, t.day))
     elif isinstance(t, (int,long,float)):
-        return tzinfo.localize(datetime.fromtimestamp(t))
+        return datetime.fromtimestamp(t, tzinfo or localtz)
     raise TypeError('expecting datetime, int, long, float, or None; got %s' %
                     type(t))
 

trac/util/tests/datefmt.py

         self.assertEqual(datefmt.to_datetime(23, tz), expected)
         self.assertEqual(datefmt.to_datetime(23L, tz), expected)
         self.assertEqual(datefmt.to_datetime(23.0, tz), expected)
+        tz = datefmt.timezone('GMT +4:00')
+        expected = datetime.datetime(1970, 1, 1, 4, 0, 23, 0, tz)
+        self.assertEqual(datefmt.to_datetime(23, tz), expected)
+        self.assertEqual(datefmt.to_datetime(23L, tz), expected)
+        self.assertEqual(datefmt.to_datetime(23.0, tz), expected)
 
-    def test_format_datetime_gmt01(self):
+    def test_format_datetime_utc(self):
         t = datetime.datetime(1970,1,1,1,0,23,0,datefmt.utc)
         expected = '1970-01-01T01:00:23Z'
         self.assertEqual(datefmt.format_datetime(t, '%Y-%m-%dT%H:%M:%SZ',
                                                  datefmt.utc), 
                                                  expected.split('T')[1])
 
-    def test_format_datetime_utc(self):
+    def test_format_datetime_gmt01(self):
         gmt01 = datefmt.FixedOffset(60, 'GMT +1:00')
         t = datetime.datetime(1970,1,1,1,0,23,0,gmt01)
         expected = '1970-01-01T01:00:23+0100'