pykolab/xml

Thomas Brüderli bruederli at kolabsys.com
Wed Oct 8 13:07:14 CEST 2014


 pykolab/xml/utils.py |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

New commits:
commit 889ecead89b87a2ff43491e3c9a7cfc6b0a0c41a
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Wed Oct 8 13:07:07 2014 +0200

    Fix timezone assignment in datetime conversion: use timezone.localize() to get dst right

diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py
index 2fe82d2..97b72af 100644
--- a/pykolab/xml/utils.py
+++ b/pykolab/xml/utils.py
@@ -57,11 +57,17 @@ def from_cdatetime(_cdatetime, with_timezone=True):
         _timezone = _cdatetime.timezone()
 
         if _timezone == '' or _timezone == None:
-            _timezone = pytz.utc
+            _dt = datetime.datetime(year, month, day, hour, minute, second, tzinfo=pytz.utc)
         else:
-            _timezone = pytz.timezone(_timezone)
-
-        return datetime.datetime(year, month, day, hour, minute, second, tzinfo=_timezone)
+            try:
+                # use pytz.timezone.localize() to correctly set DST in tzinfo according to the given date
+                _tz = pytz.timezone(_timezone)
+                _dt = _tz.localize(datetime.datetime(year, month, day, hour, minute, second))
+            except:
+                # fall back to local time
+                _dt = datetime.datetime(year, month, day, hour, minute, second)
+
+        return _dt
 
     else:
         return datetime.datetime(year, month, day, hour, minute, second)




More information about the commits mailing list