changeset 0e1c23259e75 in tryton:5.0
details: https://hg.tryton.org/tryton?cmd=changeset;node=0e1c23259e75
description:
Try to use native time zone of Windows
The dateutil implementation fails on Windows for date before epoch.
issue8145
review58541002
(grafted from f78aba02aaf00b3f3b4bc0351cddc36dcf9b4cb3)
diffstat:
doc/usage.rst | 5 -----
tryton/common/common.py | 18 +++++++++---------
2 files changed, 9 insertions(+), 14 deletions(-)
diffs (52 lines):
diff -r 5d767e82df65 -r 0e1c23259e75 doc/usage.rst
--- a/doc/usage.rst Mon Mar 04 18:58:26 2019 +0100
+++ b/doc/usage.rst Fri Mar 08 18:39:27 2019 +0100
@@ -431,11 +431,6 @@
- `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
^^^^^^^^^^^^^
diff -r 5d767e82df65 -r 0e1c23259e75 tryton/common/common.py
--- a/tryton/common/common.py Mon Mar 04 18:58:26 2019 +0100
+++ b/tryton/common/common.py Fri Mar 08 18:39:27 2019 +0100
@@ -46,7 +46,6 @@
except ImportError:
ssl = None
from threading import Lock
-import dateutil.tz
from gi.repository import Gtk
@@ -1237,16 +1236,17 @@
def timezoned_date(date, reverse=False):
- lzone = dateutil.tz.tzlocal()
- szone = dateutil.tz.tzutc()
+ try:
+ from dateutil.tz.win import tzwinlocal as tzlocal
+ except ImportError:
+ from dateutil.tz import tzlocal
+ from dateutil.tz import tzutc
+
+ lzone = tzlocal()
+ szone = tzutc()
if reverse:
lzone, szone = szone, lzone
- 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)
+ return date.replace(tzinfo=szone).astimezone(lzone).replace(tzinfo=None)
def untimezoned_date(date):