Browse Source

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

pull/325/head
Pēteris Caune 5 years ago
parent
commit
cdad632082
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 9 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +4
    -1
      hc/lib/date.py
  3. +4
    -0
      hc/lib/tests/test_date.py

+ 1
- 0
CHANGELOG.md 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) - createsuperuser management command requires an unique email address (#318)
- For superusers, show "Site Administration" in top navigation, note in README (#317) - For superusers, show "Site Administration" in top navigation, note in README (#317)
- Make Ping.body size limit configurable (#301) - Make Ping.body size limit configurable (#301)
- Show sub-second durations with higher precision, 2 digits after decimal point (#321)
### Bug Fixes ### Bug Fixes
- Increase the allowable length of Matrix room alias to 100 (#320) - Increase the allowable length of Matrix room alias to 100 (#320)


+ 4
- 1
hc/lib/date.py View File

@ -37,8 +37,11 @@ def format_duration(td):
def format_hms(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 = [] result = []
mins, secs = divmod(total_seconds, 60) mins, secs = divmod(total_seconds, 60)


+ 4
- 0
hc/lib/tests/test_date.py View File

@ -5,6 +5,10 @@ from hc.lib.date import format_hms, choose_next_report_date
class DateFormattingTestCase(TestCase): 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): def test_mins_secs_work(self):
s = format_hms(td(seconds=0)) s = format_hms(td(seconds=0))
self.assertEqual(s, "0 sec") self.assertEqual(s, "0 sec")


Loading…
Cancel
Save