Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/accessiclock/audio/tts_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def _format_natural(self, hour: int, minute: int, am_pm: str) -> str:
next_hour = hour % 12 + 1
if next_hour == 0:
next_hour = 12
return f"quarter to {next_hour} {am_pm}"
# Flip AM/PM when crossing noon (12 PM) or midnight (12 AM)
next_am_pm = ("PM" if am_pm == "AM" else "AM") if hour == 11 else am_pm
return f"quarter to {next_hour} {next_am_pm}"
else:
return f"{hour}:{minute:02d} {am_pm}"

Expand Down
30 changes: 30 additions & 0 deletions tests/test_tts_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,36 @@ def test_format_time_natural_quarter_to(self):
result = engine.format_time(time(14, 45), style="natural")
assert "quarter to" in result.lower()

def test_format_time_natural_quarter_to_noon_boundary(self):
"""At 11:45 AM, 'quarter to' should say 'quarter to 12 PM' not 'AM'."""
from accessiclock.audio.tts_engine import TTSEngine

engine = TTSEngine(force_dummy=True)
result = engine.format_time(time(11, 45), style="natural")
assert "quarter to" in result.lower()
assert "12" in result
assert "PM" in result

def test_format_time_natural_quarter_to_midnight_boundary(self):
"""At 11:45 PM, 'quarter to' should say 'quarter to 12 AM' not 'PM'."""
from accessiclock.audio.tts_engine import TTSEngine

engine = TTSEngine(force_dummy=True)
result = engine.format_time(time(23, 45), style="natural")
assert "quarter to" in result.lower()
assert "12" in result
assert "AM" in result

def test_format_time_natural_quarter_to_no_boundary(self):
"""At 2:45 PM, 'quarter to' should keep PM."""
from accessiclock.audio.tts_engine import TTSEngine

engine = TTSEngine(force_dummy=True)
result = engine.format_time(time(14, 45), style="natural")
assert "quarter to" in result.lower()
assert "3" in result
assert "PM" in result

def test_format_time_natural_irregular_minute(self):
"""Natural style with irregular minutes should show time normally."""
from accessiclock.audio.tts_engine import TTSEngine
Expand Down