Skip to content

Commit fb06d12

Browse files
committed
Handle ISO formats with a trailing Z
1 parent 9f213bf commit fb06d12

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

news/12338.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle a timezone indicator of Z when parsing dates in the self check.

src/pip/_internal/self_outdated_check.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def _get_statefile_name(key: str) -> str:
3939
return name
4040

4141

42+
def _convert_date(isodate: str) -> datetime.datetime:
43+
"""Convert an ISO format string to a date.
44+
45+
Handles the format 2020-01-22T14:24:01Z (trailing Z)
46+
which is not supported by older versions of fromisoformat.
47+
"""
48+
return datetime.datetime.fromisoformat(isodate.replace("Z", "+00:00"))
49+
50+
4251
class SelfCheckState:
4352
def __init__(self, cache_dir: str) -> None:
4453
self._state: Dict[str, Any] = {}
@@ -73,7 +82,7 @@ def get(self, current_time: datetime.datetime) -> Optional[str]:
7382
return None
7483

7584
# Determine if we need to refresh the state
76-
last_check = datetime.datetime.fromisoformat(self._state["last_check"])
85+
last_check = _convert_date(self._state["last_check"])
7786
time_since_last_check = current_time - last_check
7887
if time_since_last_check > _WEEK:
7988
return None

0 commit comments

Comments
 (0)