Correctly handle tzinfo objects parsed with dateutil. Fixes #77. Tests missing.

pull/78/merge
Johannes Raggam 2012-11-22 17:33:41 +01:00
rodzic 381097a9d5
commit 7430b66862
3 zmienionych plików z 21 dodań i 11 usunięć

Wyświetl plik

@ -4,6 +4,9 @@ Changelog
3.2dev
------
* Correctly handle tzinfo objects parsed with dateutil. Fixes #77.
[warvariuc, thet]
* Text values are escaped correclty. Fixes #74.
[warvariuc]

Wyświetl plik

@ -32,6 +32,14 @@ def unescape_char(text):
.replace(r'\;', ';')\
.replace('\\\\', '\\')
def tzinfo_from_dt(dt):
tzid = None
if hasattr(dt.tzinfo, 'zone'):
tzid = dt.tzinfo.zone # pytz implementation
elif hasattr(dt.tzinfo, 'tzname'):
tzid = dt.tzinfo.tzname(dt) # dateutil implementation
return tzid
def foldline(text, length=75, newline='\r\n'):
"""Make a string folded per RFC5545 (each line must be less than 75 octets)

Wyświetl plik

@ -53,6 +53,7 @@ from icalendar.caselessdict import CaselessDict
from icalendar.parser import Parameters
from icalendar.parser import escape_char
from icalendar.parser import unescape_char
from icalendar.parser import tzinfo_from_dt
SequenceTypes = [TupleType, ListType]
@ -557,18 +558,15 @@ class vDatetime:
def to_ical(self):
dt = self.dt
if hasattr(dt.tzinfo, 'zone'):
tzid = dt.tzinfo and dt.tzinfo.zone or None
else:
tzid = dt.tzinfo and dt.tzinfo.tzname(self.dt) or None
tzid = tzinfo_from_dt(dt)
s = "%04d%02d%02dT%02d%02d%02d" % (
self.dt.year,
self.dt.month,
self.dt.day,
self.dt.hour,
self.dt.minute,
self.dt.second
dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second
)
if tzid == 'UTC':
s += "Z"
@ -784,7 +782,8 @@ class vPeriod:
self.params = Parameters()
# set the timezone identifier
tzid = start.tzinfo and start.tzinfo.zone or None
# does not support different timezones for start and end
tzid = tzinfo_from_dt(start)
if tzid:
self.params['TZID'] = tzid