skarim / vobject

A full-featured Python package for parsing and creating iCalendar and vCard files
https://vobject.sameenkarim.com
258 stars 93 forks source link

AttributeError: 'datetime.date' object has no attribute 'tzinfo' #95

Closed voxspox closed 7 years ago

voxspox commented 7 years ago

Hi, I get the exception below from inside 'radical' during parsing a ical file. A DTSTAMP value is parsed as datetime.date, but later vobject accesses the tzinfo attribute. tzinfo is only available for datetime-objects with a time component.


File ".local/lib/python3.4/site-packages/vobject/base.py", line 1125, in readComponents
     component.transformChildrenToNative()
File ".local/lib/python3.4/site-packages/vobject/base.py", line 674, in transformChildrenToNative
     child.transformChildrenToNative()
File ".local/lib/python3.4/site-packages/vobject/base.py", line 673, in transformChildrenToNative
     child = child.transformToNative()
File ".local/lib/python3.4/site-packages/vobject/base.py", line 198, in transformToNative
     raise ParseError(msg, lineNumber)
 vobject.base.ParseError: At line 8: In transformToNative, unhandled exception on line 8: <class 'AttributeError'>: 'datetime.date' object has no attribute 'tzinfo' (<DTSTAMP{'VALUE': ['DATE']}20170916>)```
wpercy commented 7 years ago

@voxspox can you provide the ics file that threw this error?

wpercy commented 7 years ago

This is actually because the spec says that the value of "DTSTAMP" MUST be a date-time value, that is, from section 3.3.5 of RFC 5545:

Format Definition: This value type is defined by the following notation:

  date-time  = date "T" time ;As specified in the DATE and TIME
                             ;value definitions

And also, from section 3.8.7.2:

Description: The value MUST be specified in the UTC time format.

This is because DTSTAMP is meant to be a created/last-updated property. If you don't include a time, you won't necessarily be able to know which version of the calendar component is the most recently updated.