mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 09:19:31 +00:00
Remove python 2.7 requirement for format_timedelta
This commit is contained in:
parent
996fd10f8f
commit
833baae65b
1 changed files with 10 additions and 2 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue