Skip to content

Commit

Permalink
Handle ISO formats with a trailing Z
Browse files Browse the repository at this point in the history
  • Loading branch information
pfmoore committed Oct 17, 2023
1 parent 9f213bf commit fb06d12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/12338.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle a timezone indicator of Z when parsing dates in the self check.
11 changes: 10 additions & 1 deletion src/pip/_internal/self_outdated_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def _get_statefile_name(key: str) -> str:
return name


def _convert_date(isodate: str) -> datetime.datetime:
"""Convert an ISO format string to a date.
Handles the format 2020-01-22T14:24:01Z (trailing Z)
which is not supported by older versions of fromisoformat.
"""
return datetime.datetime.fromisoformat(isodate.replace("Z", "+00:00"))


class SelfCheckState:
def __init__(self, cache_dir: str) -> None:
self._state: Dict[str, Any] = {}
Expand Down Expand Up @@ -73,7 +82,7 @@ def get(self, current_time: datetime.datetime) -> Optional[str]:
return None

# Determine if we need to refresh the state
last_check = datetime.datetime.fromisoformat(self._state["last_check"])
last_check = _convert_date(self._state["last_check"])
time_since_last_check = current_time - last_check
if time_since_last_check > _WEEK:
return None
Expand Down

0 comments on commit fb06d12

Please sign in to comment.