Commit ff493c9c authored by Alexander Belopolsky's avatar Alexander Belopolsky

Issue #9527: datetime.astimezone() method will now supply a class

timezone instance corresponding to the system local timezone when
called with no arguments.
parent fdc860f3
...@@ -1501,7 +1501,7 @@ class datetime(date): ...@@ -1501,7 +1501,7 @@ class datetime(date):
localtm = _time.localtime(ts) localtm = _time.localtime(ts)
local = datetime(*localtm[:6]) local = datetime(*localtm[:6])
try: try:
# Extract TZ data if available # Extract TZ data if available
gmtoff = localtm.tm_gmtoff gmtoff = localtm.tm_gmtoff
zone = localtm.tm_zone zone = localtm.tm_zone
except AttributeError: except AttributeError:
...@@ -1517,7 +1517,7 @@ class datetime(date): ...@@ -1517,7 +1517,7 @@ class datetime(date):
tz = timezone(delta) tz = timezone(delta)
else: else:
tz = timezone(timedelta(seconds=-gmtoff), zone) tz = timezone(timedelta(seconds=-gmtoff), zone)
elif not isinstance(tz, tzinfo): elif not isinstance(tz, tzinfo):
raise TypeError("tz argument must be an instance of tzinfo") raise TypeError("tz argument must be an instance of tzinfo")
......
...@@ -3283,11 +3283,11 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase): ...@@ -3283,11 +3283,11 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
dt = self.theclass(2012, 11, 4, 6, 30, tzinfo=timezone.utc) dt = self.theclass(2012, 11, 4, 6, 30, tzinfo=timezone.utc)
local = dt.astimezone() local = dt.astimezone()
self.assertEqual(dt, local) self.assertEqual(dt, local)
self.assertEqual(local.strftime("%z %Z"), "+0500 EST") self.assertEqual(local.strftime("%z %Z"), "+0500 EST")
dt = self.theclass(2012, 11, 4, 5, 30, tzinfo=timezone.utc) dt = self.theclass(2012, 11, 4, 5, 30, tzinfo=timezone.utc)
local = dt.astimezone() local = dt.astimezone()
self.assertEqual(dt, local) self.assertEqual(dt, local)
self.assertEqual(local.strftime("%z %Z"), "+0400 EDT") self.assertEqual(local.strftime("%z %Z"), "+0400 EDT")
def test_aware_subtract(self): def test_aware_subtract(self):
cls = self.theclass cls = self.theclass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment