summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-10-08 13:07:07 +0200
committerThomas Bruederli <bruederli@kolabsys.com>2014-10-08 13:07:07 +0200
commit889ecead89b87a2ff43491e3c9a7cfc6b0a0c41a (patch)
tree14cff645bba6e8dcc6d2a0fa65a1d2510e6c0339
parentaa5fed7c899ba4681e851b616a5e2c79823494e3 (diff)
downloadpykolab-889ecead89b87a2ff43491e3c9a7cfc6b0a0c41a.tar.gz
Fix timezone assignment in datetime conversion: use timezone.localize() to get dst right
-rw-r--r--pykolab/xml/utils.py14
1 files changed, 10 insertions, 4 deletions
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)