diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/datetime.py | 6 | ||||
-rw-r--r-- | Lib/test/datetimetester.py | 6 |
2 files changed, 7 insertions, 5 deletions
diff --git a/Lib/datetime.py b/Lib/datetime.py index e4d7161..a15c6b0 100644 --- a/Lib/datetime.py +++ b/Lib/datetime.py @@ -1510,13 +1510,13 @@ class datetime(date): # implied by tm_isdst. delta = local - datetime(*_time.gmtime(ts)[:6]) dst = _time.daylight and localtm.tm_isdst > 0 - gmtoff = _time.altzone if dst else _time.timezone - if delta == timedelta(seconds=-gmtoff): + gmtoff = -(_time.altzone if dst else _time.timezone) + if delta == timedelta(seconds=gmtoff): tz = timezone(delta, _time.tzname[dst]) else: tz = timezone(delta) else: - tz = timezone(timedelta(seconds=-gmtoff), zone) + tz = timezone(timedelta(seconds=gmtoff), zone) elif not isinstance(tz, tzinfo): raise TypeError("tz argument must be an instance of tzinfo") diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 4181d4f..a417170 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -3278,16 +3278,18 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase): self.assertEqual(dt.astimezone(None), dt) self.assertEqual(dt.astimezone(), dt) + # Note that offset in TZ variable has the opposite sign to that + # produced by %z directive. @support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0') def test_astimezone_default_eastern(self): dt = self.theclass(2012, 11, 4, 6, 30, tzinfo=timezone.utc) local = dt.astimezone() 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) local = dt.astimezone() 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): cls = self.theclass |