datetime.py 868 B

12345678910111213141516171819202122232425262728
  1. """For when pip wants to check the date or time."""
  2. import datetime
  3. import sys
  4. def today_is_later_than(year: int, month: int, day: int) -> bool:
  5. today = datetime.date.today()
  6. given = datetime.date(year, month, day)
  7. return today > given
  8. def parse_iso_datetime(isodate: str) -> datetime.datetime:
  9. """Convert an ISO format string to a datetime.
  10. Handles the format 2020-01-22T14:24:01Z (trailing Z)
  11. which is not supported by older versions of fromisoformat.
  12. """
  13. # Python 3.11+ supports Z suffix natively in fromisoformat
  14. if sys.version_info >= (3, 11):
  15. return datetime.datetime.fromisoformat(isodate)
  16. else:
  17. return datetime.datetime.fromisoformat(
  18. isodate.replace("Z", "+00:00")
  19. if isodate.endswith("Z") and ("T" in isodate or " " in isodate.strip())
  20. else isodate
  21. )