Skip to content

fix(normalizer): skip zero seconds and keep o'clock in times with seconds - #602

Open
lbarrosby wants to merge 1 commit into
remsky:masterfrom
lbarrosby:fix-times-with-zero-seconds
Open

lbarrosby wants to merge 1 commit into
remsky:masterfrom
lbarrosby:fix-times-with-zero-seconds

Conversation

@lbarrosby

Copy link
Copy Markdown
Contributor

EnglishNormalizer.times reads H:MM:SS in two wrong ways:

Input Before After
It was 10:30:00 It was ten thirty and zero seconds It was ten thirty
Starts at 3:00:00 Starts at three and zero seconds Starts at three o'clock
Alarm at 10:00:05 Alarm at ten and five seconds Alarm at ten o'clock and five seconds
Logged at 9:00:00 am Logged at nine and zero seconds am Logged at nine am

The seconds field was always read, even when it was 00. Because the o'clock rule sat in the elif of the seconds branch, a whole hour followed by seconds was read as "ten and five seconds", so the minutes disappeared. Seconds are now read only when they are not zero, and the o'clock rule (no am/pm, minute 0) applies whether or not seconds follow. Times with nonzero minutes and seconds, such as 1:02:03 and 12:30:15 pm, read the same as before.

Testing

  • uv run pytest passes locally (API changes). I ran api/tests/test_normalizer*.py in a light venv without torch: 234 passed. The 2 failures in test_normalizer_redos.py are imports that venv does not have, and they fail the same way on master.
  • npm run test:web passes locally (web player changes)
  • New or changed behavior has a test. The four cases above were added to test_normalizer.py. All four fail on master and pass with this change.
  • Ran in Docker (npm run cpu:up / gpu:up), for inference or docker changes
  • CHANGELOG.md entry, if users will notice the change

ruff format --check and ruff check are clean on the touched files.

AI disclosure: written with the help of Claude Code, reviewed and tested by me.

…onds

A time with a seconds field always read the seconds, so 10:30:00 became
"ten thirty and zero seconds", and it skipped the o'clock branch, so
10:00:05 became "ten and five seconds". Read the seconds only when they
are not zero and apply the o'clock rule whether or not seconds follow.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
@RBEmerson970

Copy link
Copy Markdown

A comment: think about handling 24-hour format. For example 1:00 PM would be "thirteen hundred" in English military use. In German (whatever became of that branch?) it would be "dreizehn uhr" (i.e., different languages, different protocols).

I can see where this issue could become a rather deep rabbit hole, best not explored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants