Skip to content

Commit

Permalink
feat: Update regex to catch missing letters in am pm
Browse files Browse the repository at this point in the history
  • Loading branch information
essteer committed Jul 12, 2024
1 parent 11e4025 commit 1b3f411
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def convert_to_24_hour_time(time_str: str) -> str:
if time_str is None:
return "??:??"

match = re.match(r"(\d{1,2}):?(\d{2})?\s*(a\s?m|p\s?m)", time_str.lower())
match = re.match(r"(\d{1,2}):?(\d{2})?\s*(a\s?m|p\s?m|m)", time_str.lower())

if not match: # "late" rarely appears so don't check by default
if time_str.lower() == "late":
Expand All @@ -44,7 +44,11 @@ def convert_to_24_hour_time(time_str: str) -> str:
hour, minute, period = match.groups()
hour = int(hour)

if ("pm" in period or "p m" in period) and hour != 12:
if (
"pm" in period
or "p m" in period
or "m" == period # default to pm if first letter absent
) and hour != 12:
hour += 12
elif ("am" in period or "a m" in period) and hour == 12:
hour = 0
Expand Down

0 comments on commit 1b3f411

Please sign in to comment.