Change default sig of human duration function

This commit is contained in:
JonnyWong16 2020-10-08 19:53:32 -07:00
commit 881f37f731
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
5 changed files with 18 additions and 12 deletions

View file

@ -290,8 +290,8 @@ class DataFactory(object):
'recordsTotal': query['totalCount'],
'data': session.friendly_name_to_username(rows),
'draw': query['draw'],
'filter_duration': helpers.human_duration(filter_duration, sig='dhm', units='s'),
'total_duration': helpers.human_duration(total_duration, sig='dhm', units='s')
'filter_duration': helpers.human_duration(filter_duration, units='s'),
'total_duration': helpers.human_duration(total_duration, units='s')
}
return dict

View file

@ -166,7 +166,7 @@ class Export(object):
'tag': None
},
'duration': None,
'durationHuman': lambda o: helpers.human_duration(getattr(o, 'duration', 0), sig='dhm'),
'durationHuman': lambda o: helpers.human_duration(getattr(o, 'duration', 0)),
'fields': {
'name': None,
'locked': None
@ -362,7 +362,7 @@ class Export(object):
},
'contentRating': None,
'duration': None,
'durationHuman': lambda o: helpers.human_duration(getattr(o, 'duration', 0), sig='dhm'),
'durationHuman': lambda o: helpers.human_duration(getattr(o, 'duration', 0)),
'fields': {
'name': None,
'locked': None
@ -461,7 +461,7 @@ class Export(object):
'tag': None
},
'duration': None,
'durationHuman': lambda o: helpers.human_duration(getattr(o, 'duration', 0), sig='dhm'),
'durationHuman': lambda o: helpers.human_duration(getattr(o, 'duration', 0)),
'fields': {
'name': None,
'locked': None
@ -750,7 +750,7 @@ class Export(object):
'addedAt': helpers.datetime_to_iso,
'art': None,
'duration': None,
'durationHuman': lambda o: helpers.human_duration(getattr(o, 'duration', 0), sig='dhm'),
'durationHuman': lambda o: helpers.human_duration(getattr(o, 'duration', 0)),
'fields': {
'name': None,
'locked': None
@ -997,7 +997,7 @@ class Export(object):
'addedAt': helpers.datetime_to_iso,
'composite': None,
'duration': None,
'durationHuman': lambda o: helpers.human_duration(getattr(o, 'duration', 0), sig='dhm'),
'durationHuman': lambda o: helpers.human_duration(getattr(o, 'duration', 0)),
'guid': None,
'key': None,
'leafCount': None,

View file

@ -251,7 +251,7 @@ def datetime_to_iso(dt, to_date=False):
return dt
def human_duration(ms, sig='dhms', units='ms'):
def human_duration(ms, sig='dhm', units='ms', return_seconds=300000):
factors = {'d': 86400000,
'h': 3600000,
'm': 60000,
@ -259,6 +259,9 @@ def human_duration(ms, sig='dhms', units='ms'):
'ms': 1}
if str(ms).isdigit() and ms > 0:
if return_seconds and ms < return_seconds:
sig = 'dhms'
ms = ms * factors[units]
d, h = divmod(ms, factors['d'])