diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-01-23 20:53:10 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-01-23 20:53:10 (GMT) |
commit | 2a44a8d3320ee7bcf5d718b5bdac550c6d34db4c (patch) | |
tree | 7ac5d610e87d7a2b56e097e14525d9bc3182459f /Lib/test/test_datetime.py | |
parent | 10cadce41ec7b94aafc11b4f2c9cfb7587f5b81d (diff) | |
download | cpython-2a44a8d3320ee7bcf5d718b5bdac550c6d34db4c.zip cpython-2a44a8d3320ee7bcf5d718b5bdac550c6d34db4c.tar.gz cpython-2a44a8d3320ee7bcf5d718b5bdac550c6d34db4c.tar.bz2 |
SF bug 660872: datetimetz constructors behave counterintuitively (2.3a1).
This gives much the same treatment to datetime.fromtimestamp(stamp, tz) as
the last batch of checkins gave to datetime.now(tz): do "the obvious"
thing with the tz argument instead of a senseless thing.
Diffstat (limited to 'Lib/test/test_datetime.py')
-rw-r--r-- | Lib/test/test_datetime.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py index 7d503e0..0b9597a 100644 --- a/Lib/test/test_datetime.py +++ b/Lib/test/test_datetime.py @@ -2266,7 +2266,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase): # Try with and without naming the keyword. off42 = FixedOffset(42, "42") another = meth(ts, off42) - again = meth(ts, tzinfo=off42) + again = meth(ts, tz=off42) self.failUnless(another.tzinfo is again.tzinfo) self.assertEqual(another.utcoffset(), timedelta(minutes=42)) # Bad argument with and w/o naming the keyword. @@ -2279,6 +2279,20 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase): # Too few args. self.assertRaises(TypeError, meth) + # Try to make sure tz= actually does some conversion. + timestamp = 1000000000 # 2001-09-09 01:46:40 UTC, give or take + utc = FixedOffset(0, "utc", 0) + expected = datetime(2001, 9, 9, 1, 46, 40) + got = datetime.utcfromtimestamp(timestamp) + # We don't support leap seconds, but maybe the platfrom insists + # on using them, so don't demand exact equality). + self.failUnless(abs(got - expected) < timedelta(minutes=1)) + + est = FixedOffset(-5*60, "est", 0) + expected -= timedelta(hours=5) + got = datetime.fromtimestamp(timestamp, est).replace(tzinfo=None) + self.failUnless(abs(got - expected) < timedelta(minutes=1)) + def test_tzinfo_utcnow(self): meth = self.theclass.utcnow # Ensure it doesn't require tzinfo (i.e., that this doesn't blow up). |