-
Notifications
You must be signed in to change notification settings - Fork 0
/
outdated.py
56 lines (53 loc) · 1.52 KB
/
outdated.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def main():
month_names = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
while True:
date = input("Date: ").strip()
if "/" in date:
splitted_date = date.split("/")
if not splitted_date[0].isdigit():
continue
if int(splitted_date[0]) < 1 or int(splitted_date[0]) > 12:
continue
day = int(splitted_date[1])
if day < 1 or day > 31:
continue
month = int(splitted_date[0])
year = int(splitted_date[2])
print(f"{year:04}-{month:02}-{day:02}")
break
elif " " in date:
splitted_date = date.split(" ")
if splitted_date[0] not in month_names:
continue
month = month_names.index(splitted_date[0]) + 1
month = int(month)
if not splitted_date[1].endswith(","):
continue
day = splitted_date[1].split(",")
day = int(day[0])
if month < 1 or month > 12:
continue
if day < 1 or day > 31:
continue
year = int(splitted_date[2])
print(f"{year:04}-{month:02}-{day:02}")
break
else:
continue
if len(splitted_date) != 3:
continue
if __name__ == "__main__":
main()