mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
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.
This commit is contained in:
parent
10cadce41e
commit
2a44a8d332
4 changed files with 58 additions and 23 deletions
|
@ -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).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue