diff --git a/docs/examples.rst b/docs/examples.rst index e641191..e655f87 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -19,15 +19,15 @@ To create a calendar and write it to disk:: >>> cal = Calendar() >>> from datetime import datetime - >>> from icalendar.tools import utctz # timezone >>> cal.add('prodid', '-//My calendar product//mxm.dk//') >>> cal.add('version', '2.0') + >>> import pytz >>> event = Event() >>> event.add('summary', 'Python meeting about calendaring') - >>> event.add('dtstart', datetime(2005,4,4,8,0,0,tzinfo=utctz())) - >>> event.add('dtend', datetime(2005,4,4,10,0,0,tzinfo=utctz())) - >>> event.add('dtstamp', datetime(2005,4,4,0,10,0,tzinfo=utctz())) + >>> event.add('dtstart', datetime(2005,4,4,8,0,0,tzinfo=pytz.utc)) + >>> event.add('dtend', datetime(2005,4,4,10,0,0,tzinfo=pytz.utc)) + >>> event.add('dtstamp', datetime(2005,4,4,0,10,0,tzinfo=pytz.utc)) >>> event['uid'] = '20050115T101010/27346262376@mxm.dk' >>> event.add('priority', 5) diff --git a/src/icalendar/prop.py b/src/icalendar/prop.py index 82c122a..1338a7c 100644 --- a/src/icalendar/prop.py +++ b/src/icalendar/prop.py @@ -40,6 +40,8 @@ them directly. """ +import pytz + # from python >= 2.3 from datetime import datetime, timedelta, time, date, tzinfo from types import TupleType, ListType @@ -47,12 +49,10 @@ SequenceTypes = [TupleType, ListType] import re import time as _time import binascii -from icalendar.tools import utctz # from this package from icalendar.caselessdict import CaselessDict from icalendar.parser import Parameters -from icalendar.parser import normalized_timezone DATE_PART = r'(\d+)D' TIME_PART = r'T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?' @@ -501,8 +501,6 @@ class vDatetime: created. Be aware that there are certain limitations with timezone naive DATE-TIME components in the icalendar standard. - >>> from icalendar.tools import utctz - >>> d = datetime(2001, 1,1, 12, 30, 0) >>> dt = vDatetime(d) @@ -512,7 +510,7 @@ class vDatetime: >>> vDatetime.from_ical('20000101T120000') datetime.datetime(2000, 1, 1, 12, 0) - >>> dutc = datetime(2001, 1,1, 12, 30, 0, tzinfo=utctz()) + >>> dutc = datetime(2001, 1,1, 12, 30, 0, tzinfo=pytz.utc) >>> vDatetime(dutc).to_ical() '20010101T123000Z' @@ -551,10 +549,12 @@ class vDatetime: """ Parses the data format from ical text format. """ - # TODO: ical string should better contain also the TZID property. - + tzinfo = None if timezone: - timezone = normalized_timezone(timezone) + try: + tzinfo = pytz.timezone(timezone) + except pytz.UnknownTimeZoneError: + pass try: timetuple = map(int, (( @@ -565,12 +565,12 @@ class vDatetime: ical[11:13], # minute ical[13:15], # second ))) - if timezone: - return datetime(tzinfo=timezone, *timetuple) + if tzinfo: + return datetime(tzinfo=tzinfo, *timetuple) elif not ical[15:]: return datetime(*timetuple) elif ical[15:16] == 'Z': - return datetime(tzinfo=utctz(), *timetuple) + return datetime(tzinfo=pytz.utc, *timetuple) else: raise ValueError, ical except: diff --git a/src/icalendar/tests/example.txt b/src/icalendar/tests/example.txt index 2c8fb2e..98da09d 100644 --- a/src/icalendar/tests/example.txt +++ b/src/icalendar/tests/example.txt @@ -224,7 +224,6 @@ Init the calendar:: >>> cal = Calendar() >>> from datetime import datetime - >>> from icalendar.tools import utctz # timezone Some properties are required to be compliant:: @@ -232,12 +231,13 @@ Some properties are required to be compliant:: >>> cal.add('version', '2.0') We need at least one subcomponent for a calendar to be compliant:: - + + >>> import pytz >>> event = Event() >>> event.add('summary', 'Python meeting about calendaring') - >>> event.add('dtstart', datetime(2005,4,4,8,0,0,tzinfo=utctz())) - >>> event.add('dtend', datetime(2005,4,4,10,0,0,tzinfo=utctz())) - >>> event.add('dtstamp', datetime(2005,4,4,0,10,0,tzinfo=utctz())) + >>> event.add('dtstart', datetime(2005,4,4,8,0,0,tzinfo=pytz.utc)) + >>> event.add('dtend', datetime(2005,4,4,10,0,0,tzinfo=pytz.utc)) + >>> event.add('dtstamp', datetime(2005,4,4,0,10,0,tzinfo=pytz.utc)) A property with parameters. Notice that they are an attribute on the value:: diff --git a/src/icalendar/tools.py b/src/icalendar/tools.py index f1c9b6f..1615968 100644 --- a/src/icalendar/tools.py +++ b/src/icalendar/tools.py @@ -5,13 +5,6 @@ eh? import random from string import ascii_letters, digits from datetime import datetime -import pytz - -def utctz(): - """ Return an UTC tzinfo object from the pytz library. - - """ - return pytz.timezone('UTC') class UIDGenerator: