| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -181,16 +181,15 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: | |||
| 181 | 181 | :raise ValueError: If the format could not be understood | |
| 182 | 182 | :note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY. | |
| 183 | 183 | """ | |
| 184 | - if isinstance(string_date, datetime) and string_date.tzinfo: | ||
| 185 | - utcoffset = string_date.utcoffset() | ||
| 186 | - offset = -int(utcoffset.total_seconds()) if utcoffset else 0 | ||
| 187 | - return int(string_date.astimezone(utc).timestamp()), offset | ||
| 184 | + if isinstance(string_date, datetime): | ||
| 185 | + if string_date.tzinfo: | ||
| 186 | + utcoffset = cast(timedelta, string_date.utcoffset()) # typeguard, if tzinfoand is not None | ||
| 187 | + offset = -int(utcoffset.total_seconds()) | ||
| 188 | + return int(string_date.astimezone(utc).timestamp()), offset | ||
| 189 | + else: | ||
| 190 | + raise ValueError(f"Unsupported date format or type: {string_date}" % string_date) | ||
| 188 | 191 | ||
| 189 | 192 | else: | |
| 190 | - assert isinstance(string_date, str), f"string_date={string_date}, type={type(string_date)}" # for mypy | ||
| 191 | - | ||
| 192 | - # git time | ||
| 193 | - try: | ||
| 194 | 193 | if string_date.count(' ') == 1 and string_date.rfind(':') == -1: | |
| 195 | 194 | timestamp, offset_str = string_date.split() | |
| 196 | 195 | if timestamp.startswith('@'): | |
@@ -244,13 +243,9 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: | |||
| 244 | 243 | continue | |
| 245 | 244 | # END exception handling | |
| 246 | 245 | # END for each fmt | |
| 247 | - | ||
| 248 | 246 | # still here ? fail | |
| 249 | 247 | raise ValueError("no format matched") | |
| 250 | 248 | # END handle format | |
| 251 | - except Exception as e: | ||
| 252 | - raise ValueError("Unsupported date format: %s" % string_date) from e | ||
| 253 | - # END handle exceptions | ||
| 254 | 249 | ||
| 255 | 250 | ||
| 256 | 251 | # precompiled regex | |
| Back | FazBrowse Home | New Git URL |
0 commit comments