diff options
author | Yobmod <yobmod@gmail.com> | 2021-08-02 17:09:03 +0100 |
---|---|---|
committer | Yobmod <yobmod@gmail.com> | 2021-08-02 17:09:03 +0100 |
commit | 024b69669811dc3aa5a018eb3df5535202edf5f9 (patch) | |
tree | d918a5b543b7f80f8b5b3eb3a6ecdfe648fb768b /git/objects/util.py | |
parent | 2fe13cad9c889b8628119ab5ee139038b0c164fd (diff) | |
download | gitpython-024b69669811dc3aa5a018eb3df5535202edf5f9.tar.gz |
Fix parse_date typing 4
Diffstat (limited to 'git/objects/util.py')
-rw-r--r-- | git/objects/util.py | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/git/objects/util.py b/git/objects/util.py index 6e3f688e..1ca6f050 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -181,16 +181,15 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: :raise ValueError: If the format could not be understood :note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY. """ - if isinstance(string_date, datetime) and string_date.tzinfo: - utcoffset = string_date.utcoffset() - offset = -int(utcoffset.total_seconds()) if utcoffset else 0 - return int(string_date.astimezone(utc).timestamp()), offset + if isinstance(string_date, datetime): + if string_date.tzinfo: + utcoffset = cast(timedelta, string_date.utcoffset()) # typeguard, if tzinfoand is not None + offset = -int(utcoffset.total_seconds()) + return int(string_date.astimezone(utc).timestamp()), offset + else: + raise ValueError(f"Unsupported date format or type: {string_date}" % string_date) else: - assert isinstance(string_date, str), f"string_date={string_date}, type={type(string_date)}" # for mypy - - # git time - try: if string_date.count(' ') == 1 and string_date.rfind(':') == -1: timestamp, offset_str = string_date.split() if timestamp.startswith('@'): @@ -244,13 +243,9 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: continue # END exception handling # END for each fmt - # still here ? fail raise ValueError("no format matched") # END handle format - except Exception as e: - raise ValueError("Unsupported date format: %s" % string_date) from e - # END handle exceptions # precompiled regex |