From 8a06d8fdf3b75aac459da612e4dc40851d5def2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Br=C3=BCheim?= Date: Tue, 7 Feb 2023 22:00:42 +0100 Subject: [PATCH] improve datetime handling a tiny bit --- packagecontrol.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packagecontrol.py b/packagecontrol.py index 02a28a1..2510b3a 100644 --- a/packagecontrol.py +++ b/packagecontrol.py @@ -490,17 +490,20 @@ def _get_available_packages(self, force=False): finally: self.__list_updating = False - def _make_date(self, date_str): + def _make_date(self, date): """Parses a isoformat datetime string to an datetime-object Don't look at this, just don't """ - if re.search(r"[+\-]\d\d:\d\d$", date_str): - date_str = date_str[:-3] + date_str[-2:] - elif date_str[-5] != '-' and date_str[-5] != '+': - date_str += "+0000" + if isinstance(date, datetime.datetime): + return date - return datetime.datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S%z") + if re.search(r"[+\-]\d\d:\d\d$", date): + date = date[:-3] + date[-2:] + elif date[-5] != '-' and date[-5] != '+': + date += "+0000" + + return datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%S%z") def _get_last_run(self): """Reads the time of the last run from file