Queer European MD passionate about IT

outdated.py 904 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import re
  2. months = [
  3. "January",
  4. "February",
  5. "March",
  6. "April",
  7. "May",
  8. "June",
  9. "July",
  10. "August",
  11. "September",
  12. "October",
  13. "November",
  14. "December"
  15. ]
  16. def main():
  17. while True:
  18. try:
  19. entered_date = input("Date: ").strip()
  20. except Exception:
  21. continue
  22. if re.match(r"\d+/\d+/\d+", entered_date):
  23. month, day, year = map(int, entered_date.split('/'))
  24. elif re.match(r"\w+ \d{1,2}, \d{4}", entered_date):
  25. entered_date = entered_date.replace(",", "")
  26. month, day, year = entered_date.split(' ')
  27. month = months.index(month) + 1
  28. day, year = map(int, (day, year))
  29. else:
  30. continue
  31. if month > 12 or day > 31:
  32. continue
  33. break
  34. print(f"{year:04d}-{month:02d}-{day:02d}")
  35. if __name__ == "__main__":
  36. main()