Do not fail on timezone operation before epoch on Windows

dateutil fails to use tzlocal on Windows for datetime before epoch.
So we just skip the timezone conversion which result in using UTC.

issue4582
review36231003
This commit is contained in:
Cédric Krier committed 2018-04-22 00:24:54 +02:00
1 parent d7789273af
commit b4e48bd549
2 files changed
+12 -2

No files matched your search

+5
View File
@@ -593,6 +593,11 @@ increases if lower case or decreases if upper case:
- `i`: by one minute
- `s`: by one second
.. warn::
Under Windows, the datetime before 1970 are shown in UTC instead of the
local timezone.
..
Search Widget
^^^^^^^^^^^^^
+7 -2
View File
@@ -1344,11 +1344,16 @@ def timezoned_date(date, reverse=False):
szone = dateutil.tz.tzutc()
if reverse:
lzone, szone = szone, lzone
return date.replace(tzinfo=szone).astimezone(lzone).replace(tzinfo=None)
try:
return (date.replace(tzinfo=szone).astimezone(lzone)
.replace(tzinfo=None))
except (ValueError, OSError):
# https://github.com/dateutil/dateutil/issues/434
return date.replace(tzinfo=None)
def untimezoned_date(date):
return timezoned_date(date, reverse=True).replace(tzinfo=None)
return timezoned_date(date, reverse=True)
def humanize(size):