kopia lustrzana https://github.com/collective/icalendar
Correctly handle tzinfo objects parsed with dateutil. Fixes #77. Tests missing.
rodzic
381097a9d5
commit
7430b66862
|
@ -4,6 +4,9 @@ Changelog
|
||||||
3.2dev
|
3.2dev
|
||||||
------
|
------
|
||||||
|
|
||||||
|
* Correctly handle tzinfo objects parsed with dateutil. Fixes #77.
|
||||||
|
[warvariuc, thet]
|
||||||
|
|
||||||
* Text values are escaped correclty. Fixes #74.
|
* Text values are escaped correclty. Fixes #74.
|
||||||
[warvariuc]
|
[warvariuc]
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,14 @@ def unescape_char(text):
|
||||||
.replace(r'\;', ';')\
|
.replace(r'\;', ';')\
|
||||||
.replace('\\\\', '\\')
|
.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'):
|
def foldline(text, length=75, newline='\r\n'):
|
||||||
"""Make a string folded per RFC5545 (each line must be less than 75 octets)
|
"""Make a string folded per RFC5545 (each line must be less than 75 octets)
|
||||||
|
|
|
@ -53,6 +53,7 @@ from icalendar.caselessdict import CaselessDict
|
||||||
from icalendar.parser import Parameters
|
from icalendar.parser import Parameters
|
||||||
from icalendar.parser import escape_char
|
from icalendar.parser import escape_char
|
||||||
from icalendar.parser import unescape_char
|
from icalendar.parser import unescape_char
|
||||||
|
from icalendar.parser import tzinfo_from_dt
|
||||||
|
|
||||||
|
|
||||||
SequenceTypes = [TupleType, ListType]
|
SequenceTypes = [TupleType, ListType]
|
||||||
|
@ -557,18 +558,15 @@ class vDatetime:
|
||||||
|
|
||||||
def to_ical(self):
|
def to_ical(self):
|
||||||
dt = self.dt
|
dt = self.dt
|
||||||
if hasattr(dt.tzinfo, 'zone'):
|
tzid = tzinfo_from_dt(dt)
|
||||||
tzid = dt.tzinfo and dt.tzinfo.zone or None
|
|
||||||
else:
|
|
||||||
tzid = dt.tzinfo and dt.tzinfo.tzname(self.dt) or None
|
|
||||||
|
|
||||||
s = "%04d%02d%02dT%02d%02d%02d" % (
|
s = "%04d%02d%02dT%02d%02d%02d" % (
|
||||||
self.dt.year,
|
dt.year,
|
||||||
self.dt.month,
|
dt.month,
|
||||||
self.dt.day,
|
dt.day,
|
||||||
self.dt.hour,
|
dt.hour,
|
||||||
self.dt.minute,
|
dt.minute,
|
||||||
self.dt.second
|
dt.second
|
||||||
)
|
)
|
||||||
if tzid == 'UTC':
|
if tzid == 'UTC':
|
||||||
s += "Z"
|
s += "Z"
|
||||||
|
@ -784,7 +782,8 @@ class vPeriod:
|
||||||
|
|
||||||
self.params = Parameters()
|
self.params = Parameters()
|
||||||
# set the timezone identifier
|
# 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:
|
if tzid:
|
||||||
self.params['TZID'] = tzid
|
self.params['TZID'] = tzid
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue