Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8440761

Browse files
committed
SF bug 680864: test_datetime fails for non-unix epoch
Apparently MAC OS 9 doesn't have POSIX-conforming timestamps. A test fails as a result, but at least for this specific test it's easy enough to get the POSIX epoch out of it.
1 parent cc1fccb commit 8440761

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

Lib/test/test_datetime.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,18 +2257,17 @@ def test_tzinfo_fromtimestamp(self):
22572257
self.assertRaises(TypeError, meth)
22582258

22592259
# Try to make sure tz= actually does some conversion.
2260-
timestamp = 1000000000 # 2001-09-09 01:46:40 UTC, give or take
2261-
utc = FixedOffset(0, "utc", 0)
2262-
expected = datetime(2001, 9, 9, 1, 46, 40)
2263-
got = datetime.utcfromtimestamp(timestamp)
2264-
# We don't support leap seconds, but maybe the platfrom insists
2265-
# on using them, so don't demand exact equality).
2266-
self.failUnless(abs(got - expected) < timedelta(minutes=1))
2267-
2268-
est = FixedOffset(-5*60, "est", 0)
2269-
expected -= timedelta(hours=5)
2270-
got = datetime.fromtimestamp(timestamp, est).replace(tzinfo=None)
2271-
self.failUnless(abs(got - expected) < timedelta(minutes=1))
2260+
timestamp = 1000000000
2261+
utcdatetime = datetime.utcfromtimestamp(timestamp)
2262+
# In POSIX (epoch 1970), that's 2001-09-09 01:46:40 UTC, give or take.
2263+
# But on some flavor of Mac, it's nowhere near that. So we can't have
2264+
# any idea here what time that actually is, we can only test that
2265+
# relative changes match.
2266+
utcoffset = timedelta(hours=-15, minutes=39) # arbitrary, but not zero
2267+
tz = FixedOffset(utcoffset, "tz", 0)
2268+
expected = utcdatetime + utcoffset
2269+
got = datetime.fromtimestamp(timestamp, tz)
2270+
self.assertEqual(expected, got.replace(tzinfo=None))
22722271

22732272
def test_tzinfo_utcnow(self):
22742273
meth = self.theclass.utcnow

0 commit comments

Comments
 (0)