Merge 854fc555d68f149e54c5bc53baaea5a3abe94b5a into 6d51ffceafbf240145619af4c92408a6e54b7924

This commit is contained in:
Sash 2026-11-14 19:02:26 +09:00 committed by GitHub
commit e77aef2525
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View File

@ -86,7 +86,10 @@ def _expand_time(m):
"""
hours, minutes = map(int, m.group(1, 2))
period = "a.m." if hours < 12 else "p.m."
if hours > 12:
# 00:00 is midnight. On a 12-hour clock that hour is twelve, not zero.
if hours == 0:
hours = 12
elif hours > 12:
hours -= 12
hour_word = _inflect.number_to_words(hours)

View File

@ -0,0 +1,22 @@
import os
import sys
import unittest
sys.path.insert(0, os.path.dirname(__file__))
from expend import normalize
class TimeTests(unittest.TestCase):
def test_midnight_is_twelve_am(self):
self.assertEqual(normalize("0:00"), "twelve o'clock a.m.")
self.assertEqual(normalize("00:30"), "twelve thirty a.m.")
def test_noon_and_afternoon_stay(self):
self.assertEqual(normalize("12:00"), "twelve o'clock p.m.")
self.assertEqual(normalize("4:00"), "four o'clock a.m.")
self.assertEqual(normalize("13:00"), "one o'clock p.m.")
self.assertEqual(normalize("13:30"), "one thirty p.m.")
if __name__ == "__main__":
unittest.main()