-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.py
24 lines (21 loc) · 766 Bytes
/
lib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import re
def normalize_date(s: str) -> str:
# Split into words, separated by `,` or a space. This is meant to handle how sometimes
# there will be multiple dates, or there will be extra words like `Saturday`.
words = re.split(r",|\s", s)
new_words = []
for word in words:
if not word.strip():
continue
if word.count("/") != 2:
new_words.append(word)
continue
day, month, year = word.split("/")
likely_thai_year = len(year) == 2 and "6" <= year[0] < ":"
if likely_thai_year:
try:
year = str(int(year) - 43)
except TypeError:
pass
new_words.append(f"{month}/{day}/{year}")
return " ".join(new_words)