Show sub-second durations with higher precision, 2 digits after decimal point. Fixes #321

This commit is contained in:
Pēteris Caune 2020-01-17 14:41:41 +02:00
parent 77033760f9
commit cdad632082
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
3 changed files with 9 additions and 1 deletions

View File

@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- createsuperuser management command requires an unique email address (#318)
- For superusers, show "Site Administration" in top navigation, note in README (#317)
- Make Ping.body size limit configurable (#301)
- Show sub-second durations with higher precision, 2 digits after decimal point (#321)
### Bug Fixes
- Increase the allowable length of Matrix room alias to 100 (#320)

View File

@ -37,8 +37,11 @@ def format_duration(td):
def format_hms(td):
total_seconds = int(td.total_seconds())
total_seconds = td.total_seconds()
if 0.01 <= total_seconds < 1:
return "%.2f sec" % total_seconds
total_seconds = int(total_seconds)
result = []
mins, secs = divmod(total_seconds, 60)

View File

@ -5,6 +5,10 @@ from hc.lib.date import format_hms, choose_next_report_date
class DateFormattingTestCase(TestCase):
def test_sub_second_works(self):
s = format_hms(td(seconds=0.12))
self.assertEqual(s, "0.12 sec")
def test_mins_secs_work(self):
s = format_hms(td(seconds=0))
self.assertEqual(s, "0 sec")