-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOutdated
More file actions
44 lines (36 loc) · 1.25 KB
/
Outdated
File metadata and controls
44 lines (36 loc) · 1.25 KB
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
def main():
months = {
"January": 1, "February": 2, "March": 3, "April": 4,
"May": 5, "June": 6, "July": 7, "August": 8,
"September": 9, "October": 10, "November": 11, "December": 12
}
while True:
try:
date = input("Date: ").strip()
# Format: MM/DD/YYYY
if "/" in date:
parts = date.split("/")
if len(parts) != 3:
raise ValueError
month, day, year = map(int, parts)
# Format: Month D, YYYY
elif "," in date:
month_day, year = date.split(",")
month_name, day = month_day.strip().split(" ")
month = months.get(month_name)
if month is None:
raise ValueError
day = int(day)
year = int(year.strip())
else:
raise ValueError
# Validate basic bounds
if not (1 <= month <= 12 and 1 <= day <= 31):
raise ValueError
# Print ISO format
print(f"{year:04}-{month:02}-{day:02}")
break
except ValueError:
continue # Reprompt on bad input
if __name__ == "__main__":
main()