From 3ee08339957a98a31edecad67c239138ce4f301a Mon Sep 17 00:00:00 2001 From: Alvin Wan Date: Thu, 16 Jan 2025 23:31:31 -0800 Subject: [PATCH] support o'clock - fixes #12 (second half) --- tests/test_e2e.py | 3 +-- timefhuman/grammar.lark | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_e2e.py b/tests/test_e2e.py index fe01135..763701d 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -79,7 +79,7 @@ def test_default(now, test_input, expected): @pytest.mark.parametrize("test_input, expected", [ # time only ('5p', datetime.time(hour=17, minute=0)), - # ("3 o'clock", datetime.time(hour=3, minute=0)), + ("3 o'clock pm", datetime.time(hour=15, minute=0)), # fixes gh#12 # date only ('July 2019', datetime.date(2019, 7, 1)), @@ -112,7 +112,6 @@ def test_default(now, test_input, expected): ('30-40 mins', (datetime.timedelta(minutes=30), datetime.timedelta(minutes=40))), ('1 or 2 days', [datetime.timedelta(days=1), datetime.timedelta(days=2)]), - # TODO: support "3 o'clock" # TODO: support "quarter to 3" # TODO: support "one and a half hours" diff --git a/timefhuman/grammar.lark b/timefhuman/grammar.lark index 18dac45..f86b579 100644 --- a/timefhuman/grammar.lark +++ b/timefhuman/grammar.lark @@ -77,7 +77,7 @@ date: month "/" day "/" year // However, that means to support single-integer (e.g., hour) times, we need // to manually add them to the `datetime` rule above. time: hour ":" minute meridiem? - | hour meridiem + | hour ("o'clock")? meridiem | timename duration: ("in"|"for")? duration_part (("and"|",")? duration_part)* ("ago")?