[IMP] runbot: use babel helper to format timedelta

It allow minimal granularity to minutes and rollover thresholds.
This commit is contained in:
Christophe Simonis 2019-06-27 17:41:03 +02:00 committed by Christophe Simonis
parent 857821e41a
commit 059957282e

View File

@ -11,6 +11,9 @@ import socket
import time import time
from collections import OrderedDict from collections import OrderedDict
from datetime import timedelta
from babel.dates import format_timedelta
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
@ -83,11 +86,11 @@ def rfind(filename, pattern):
def s2human(time): def s2human(time):
"""Convert a time in second into an human readable string""" """Convert a time in second into an human readable string"""
for delay, desc in [(86400, 'd'),(3600, 'h'),(60, 'm')]: return format_timedelta(
if time >= delay: timedelta(seconds=time),
return str(int(time / delay)) + desc format="narrow",
return str(int(time)) + "s" threshold=2.1,
)
@contextlib.contextmanager @contextlib.contextmanager
def local_pgadmin_cursor(): def local_pgadmin_cursor():