mirror of https://github.com/snachodog/mybuddy.git
Add a short param to the duration_string for XhXmXs formatted durations.
This commit is contained in:
parent
463dd0c1d7
commit
1185addace
|
@ -126,7 +126,8 @@ class Timer(models.Model):
|
||||||
return 'Timer ({})'.format(self.name)
|
return 'Timer ({})'.format(self.name)
|
||||||
|
|
||||||
def duration(self):
|
def duration(self):
|
||||||
return duration_string(self.start, self.end or timezone.now())
|
return duration_string(self.start, self.end or timezone.now(),
|
||||||
|
short=True)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
self.active = self.end is None
|
self.active = self.end is None
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
{% for timer in timers %}
|
{% for timer in timers %}
|
||||||
{{ timer.name }} ({{ timer.duration }})
|
{{ timer.name }} ({{ timer.duration }})<br/>
|
||||||
{% endfor %}
|
{% endfor %}
|
|
@ -4,13 +4,16 @@ from __future__ import unicode_literals
|
||||||
from math import floor
|
from math import floor
|
||||||
|
|
||||||
|
|
||||||
def duration_string(start, end):
|
def duration_string(start, end, short=False):
|
||||||
diff = end - start
|
diff = end - start
|
||||||
h = floor(diff.seconds / 3600)
|
h = floor(diff.seconds / 3600)
|
||||||
m = floor((diff.seconds - h * 3600) / 60)
|
m = floor((diff.seconds - h * 3600) / 60)
|
||||||
s = diff.seconds % 60
|
s = diff.seconds % 60
|
||||||
|
|
||||||
duration = ''
|
duration = ''
|
||||||
|
if short:
|
||||||
|
duration = '{}h {}m {}s'.format(h, m, s)
|
||||||
|
else:
|
||||||
if h > 0:
|
if h > 0:
|
||||||
duration = '{} hour{}'.format(h, 's' if h > 1 else '')
|
duration = '{} hour{}'.format(h, 's' if h > 1 else '')
|
||||||
if m > 0:
|
if m > 0:
|
||||||
|
|
Loading…
Reference in New Issue