diff --git a/src/accessiclock/audio/tts_engine.py b/src/accessiclock/audio/tts_engine.py index e6f4f87..535161a 100644 --- a/src/accessiclock/audio/tts_engine.py +++ b/src/accessiclock/audio/tts_engine.py @@ -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}" diff --git a/tests/test_tts_engine.py b/tests/test_tts_engine.py index 8122bc0..ac98fa5 100644 --- a/tests/test_tts_engine.py +++ b/tests/test_tts_engine.py @@ -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