def test_total_seconds(self): d = Duration(days=365) self.assertEqual(d.total_seconds(), 31536000.0) for total_seconds in [123456.789012, -123456.789012, 0.123456, 0, 1e6]: d = Duration(seconds=total_seconds) self.assertEqual(d.total_seconds(), total_seconds) # Issue8644: Test that d.total_seconds() has the same # accuracy as d / Duration(seconds=1). for ms in [-1, -2, -123]: d = Duration(microseconds=ms) self.assertEqual(d.total_seconds(), d / Duration(seconds=1))
def test_accuracy(self): tiny = Duration.resolution # Make sure we can make a Duration that uses Long: m = Duration(2 ** 65, seconds=1234, microseconds=567890) # The total_microseconds() can give as accuracy: self.assertEqual(m.total_microseconds(), 3187597375937010519246034567890) # Float can handle this many days: self.assertEqual(m.days, int(m.total_days())) # Float does not have the accuracy for the seconds in this case: self.assertEqual(m.total_microseconds() - int(m.total_seconds() * 1000000), 1234567890) self.assertEqual(m.total_microseconds() - int(m.total_days() * 86400000000), 1234567890)