Skip to content

Commit 4ec42ab

Browse files
committed
Piwik: Format durations in a nicer way
1 parent 28f56b8 commit 4ec42ab

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

piwik/indico_piwik/queries/utils.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
# see the LICENSE file for more details.
77

88
import json
9+
from datetime import timedelta
910
from functools import reduce
1011

1112
from flask_pluginengine import current_plugin
1213

14+
from indico.util.date_time import format_human_timedelta
15+
1316

1417
def get_json_from_remote_server(func, **kwargs):
1518
"""
@@ -37,18 +40,6 @@ def reduce_json(data):
3740
return reduce(lambda x, y: int(x) + int(y), list(data.values()))
3841

3942

40-
def stringify_seconds(seconds=0):
41-
"""
42-
Takes time as a value of seconds and deduces the delta in human-readable
43-
HHh MMm SSs format.
44-
"""
45-
seconds = int(seconds)
46-
minutes = seconds / 60
47-
48-
h = m = s = 0
49-
if seconds > 0:
50-
s = seconds % 60
51-
m = minutes % 60
52-
h = minutes / 60
53-
54-
return f'{h}h {m}m {s}s'
43+
def stringify_seconds(seconds):
44+
"""Format seconds in a compact HHh MMm SSs format."""
45+
return format_human_timedelta(timedelta(seconds=seconds), narrow=True)

0 commit comments

Comments
 (0)