changeset c4a08d4a878c in tryton:4.8
details: https://hg.tryton.org/tryton?cmd=changeset;node=c4a08d4a878c
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 75212322ca1b -r c4a08d4a878c 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
@@ -593,11 +593,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 75212322ca1b -r c4a08d4a878c 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
@@ -38,7 +38,6 @@
except ImportError:
ssl = None
from threading import Lock
-import dateutil.tz
from gi.repository import Gtk
@@ -1340,16 +1339,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):