mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Issue #5788: datetime.timedelta objects get a new total_seconds() method returning
the total number of seconds in the duration. Patch by Brian Quinlan.
This commit is contained in:
parent
0d9f61a543
commit
bcfaf8007d
4 changed files with 33 additions and 1 deletions
|
|
@ -266,6 +266,13 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
|
|||
self.assertEqual(td.seconds, seconds)
|
||||
self.assertEqual(td.microseconds, us)
|
||||
|
||||
def test_total_seconds(self):
|
||||
td = timedelta(days=365)
|
||||
self.assertEqual(td.total_seconds(), 31536000.0)
|
||||
for total_seconds in [123456.789012, -123456.789012, 0.123456, 0, 1e6]:
|
||||
td = timedelta(seconds=total_seconds)
|
||||
self.assertEqual(td.total_seconds(), total_seconds)
|
||||
|
||||
def test_carries(self):
|
||||
t1 = timedelta(days=100,
|
||||
weeks=-7,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue