You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
839 B

  1. from datetime import timedelta as td
  2. from django.test import TestCase
  3. from hc.lib.date import format_hms
  4. class DateFormattingTestCase(TestCase):
  5. def test_sub_second_works(self):
  6. s = format_hms(td(seconds=0.12))
  7. self.assertEqual(s, "0.12 sec")
  8. def test_mins_secs_work(self):
  9. s = format_hms(td(seconds=0))
  10. self.assertEqual(s, "0 sec")
  11. s = format_hms(td(seconds=1))
  12. self.assertEqual(s, "1 sec")
  13. s = format_hms(td(seconds=61))
  14. self.assertEqual(s, "1 min 1 sec")
  15. s = format_hms(td(seconds=62))
  16. self.assertEqual(s, "1 min 2 sec")
  17. def test_hours_work(self):
  18. s = format_hms(td(seconds=62 + 60 * 60))
  19. self.assertEqual(s, "1 h 1 min 2 sec")
  20. s = format_hms(td(seconds=60 * 60))
  21. self.assertEqual(s, "1 h 0 min 0 sec")