1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 01:37:20 +00:00

Remove python 2.7 requirement for format_timedelta

This commit is contained in:
Jonas Borgström 2011-08-08 20:55:09 +02:00
parent 996fd10f8f
commit 833baae65b

View file

@ -212,8 +212,16 @@ def format_time(t):
def format_timedelta(td): def format_timedelta(td):
"""Format timedelta in a human friendly format""" """Format timedelta in a human friendly format
ts = td.total_seconds()
>>> from datetime import datetime
>>> t0 = datetime(2001, 1, 1, 10, 20, 3, 0)
>>> t1 = datetime(2001, 1, 1, 12, 20, 4, 100000)
>>> format_timedelta(t1 - t0)
'2 hours 1.10 seconds'
"""
# Since td.total_seconds() requires python 2.7
ts = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / float(10**6)
s = ts % 60 s = ts % 60
m = int(ts / 60) % 60 m = int(ts / 60) % 60
h = int(ts / 3600) % 24 h = int(ts / 3600) % 24