Skip to content

Commit

Permalink
Fix todo dtstart values for floating due dates (#313)
Browse files Browse the repository at this point in the history
* Fix for dtstart persisted with an invalid timezone

* Remove comments

* Entirely remove invalid dtstart values

* Bump to 7.0.3

* Address lint errors
  • Loading branch information
allenporter authored Mar 15, 2024
1 parent 7f1e660 commit 219071f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
29 changes: 3 additions & 26 deletions ical/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .component import ComponentModel, validate_until_dtstart, validate_recurrence_dates
from .exceptions import CalendarParseError
from .iter import RulesetIterable
from .parsing.property import ParsedProperty, ParsedPropertyParameter
from .parsing.property import ParsedProperty
from .timespan import Timespan
from .types import (
CalAddress,
Expand All @@ -37,7 +37,6 @@
RequestStatus,
Uri,
RelatedTo,
date_time,
)
from .util import dtstamp_factory, normalize_datetime, uid_factory, local_timezone

Expand Down Expand Up @@ -376,35 +375,13 @@ def _parse_single_property(cls, field_type: type, prop: ParsedProperty) -> Any:
and field_type == datetime.datetime
and prop.params is not None
):
new_prop = ParsedProperty(
prop.name, prop.value, _repair_tzid_param(prop.params)
)
_LOGGER.debug(
"Applying todo dtstart repair for invalid timezone: %s", new_prop
"Applying todo dtstart repair for invalid timezone; Removing dtstart",
)
try:
return date_time.parse_property_value(new_prop)
except ValueError as repair_err:
_LOGGER.debug(
"To-do dtstart repair failed %s, raising original error",
repair_err,
)
return None
raise err

_validate_until_dtstart = root_validator(allow_reuse=True)(validate_until_dtstart)
_validate_recurrence_dates = root_validator(allow_reuse=True)(
validate_recurrence_dates
)


def _repair_tzid_param(
params: list[ParsedPropertyParameter],
) -> list[ParsedPropertyParameter]:
"""Repair the TZID parameter."""
result_params = []
for param in params:
if param.name == "TZID":
result_params.append(ParsedPropertyParameter(param.name, ["UTC"]))
continue
result_params.append(param)
return result_params
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ical
version = 7.0.2
version = 7.0.3
description = Python iCalendar implementation (rfc 2445)
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
26 changes: 22 additions & 4 deletions tests/__snapshots__/test_calendar_stream.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,6 @@
]),
'classification': 'CONFIDENTIAL',
'dtstamp': '2007-03-13T12:34:32+00:00',
'dtstart': '2007-05-01T11:00:00+00:00',
'due': '2007-05-01T11:00:00-07:00',
'status': 'NEEDS-ACTION',
'summary': 'Submit Quebec Income Tax Return for 2006',
Expand All @@ -1110,13 +1109,24 @@
dict({
'completed': '2007-07-07T10:00:00+00:00',
'dtstamp': '2007-05-14T10:32:11+00:00',
'dtstart': '2007-05-14T11:00:00+00:00',
'due': '2007-07-09T13:00:00+00:00',
'priority': 1,
'status': 'NEEDS-ACTION',
'summary': 'Submit Revised Internet-Draft',
'uid': '[email protected]',
}),
dict({
'categories': list([
'FAMILY',
'FINANCE',
]),
'classification': 'CONFIDENTIAL',
'dtstamp': '2007-03-13T12:34:32+00:00',
'due': '2007-05-01T11:00:00',
'status': 'NEEDS-ACTION',
'summary': 'Floating due datetime',
'uid': '[email protected]',
}),
]),
'version': '2.0',
}),
Expand Down Expand Up @@ -1845,7 +1855,6 @@
CATEGORIES:FAMILY
CATEGORIES:FINANCE
CLASS:CONFIDENTIAL
DTSTART:20070501T110000Z
DUE;TZID=America/Los_Angeles:20070501T110000
STATUS:NEEDS-ACTION
SUMMARY:Submit Quebec Income Tax Return for 2006
Expand All @@ -1854,12 +1863,21 @@
DTSTAMP:20070514T103211Z
UID:[email protected]
COMPLETED:20070707T100000Z
DTSTART:20070514T110000Z
DUE:20070709T130000Z
PRIORITY:1
STATUS:NEEDS-ACTION
SUMMARY:Submit Revised Internet-Draft
END:VTODO
BEGIN:VTODO
DTSTAMP:20070313T123432Z
UID:[email protected]
CATEGORIES:FAMILY
CATEGORIES:FINANCE
CLASS:CONFIDENTIAL
DUE:20070501T110000
STATUS:NEEDS-ACTION
SUMMARY:Floating due datetime
END:VTODO
END:VCALENDAR
'''
# ---
Expand Down
10 changes: 10 additions & 0 deletions tests/testdata/todo-invalid-dtstart-tzid.ics
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,14 @@ COMPLETED:20070707T100000Z
PRIORITY:1
STATUS:NEEDS-ACTION
END:VTODO
BEGIN:VTODO
UID:20070313T123432Z[email protected]
DTSTAMP:20070313T123432Z
SUMMARY:Floating due datetime
DTSTART;TZID=CST:20070501T110000
DUE:20070501T110000
CLASS:CONFIDENTIAL
CATEGORIES:FAMILY,FINANCE
STATUS:NEEDS-ACTION
END:VTODO
END:VCALENDAR

0 comments on commit 219071f

Please sign in to comment.