Skip to content

Commit

Permalink
fix for issue #352 and refactored some usage of vobject into icalenda…
Browse files Browse the repository at this point in the history
…r. More test code is needed, since this refactoring may break things.
  • Loading branch information
tobixen committed Dec 8, 2023
1 parent caa4cde commit 95370cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Some bugfixes.
* Bugfix that a 500 internal server error could cause an recursion loop, credits to github user @bchardin in https://github.com/python-caldav/caldav/pull/344
* Compatibility-fix for Google calendar, credits to github user @e-katov in https://github.com/python-caldav/caldav/pull/344
* Spelling, grammar and removing a useless regexp, credits to github user @scop in https://github.com/python-caldav/caldav/pull/337
* Faulty icalendar code caused the code for fixing faulty icalendar code to break, credits to github user @yuwash in https://github.com/python-caldav/caldav/pull/347
* Faulty icalendar code caused the code for fixing faulty icalendar code to break, credits to github user @yuwash in https://github.com/python-caldav/caldav/pull/347 and https://github.com/python-caldav/caldav/pull/350

## [1.3.6] - 2023-07-20

Expand Down
24 changes: 12 additions & 12 deletions caldav/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,33 +1111,33 @@ def search(

def sort_key_func(x):
ret = []
for objtype in ("vtodo", "vevent", "vjournal"):
if hasattr(x.instance, objtype):
vobj = getattr(x.instance, objtype)
break
comp = x.icalendar_component
defaults = {
"due": "2050-01-01",
"dtstart": "1970-01-01",
"priority": "0",
"priority": 0,
## Usage of strftime is a simple way to ensure there won't be
## problems if comparing dates with timestamps
"isnt_overdue": not (
hasattr(vobj, "due")
and vobj.due.value.strftime("%F%H%M%S")
'due' in comp and
comp['due'].dt.strftime("%F%H%M%S")
< datetime.now().strftime("%F%H%M%S")
),
"hasnt_started": (
hasattr(vobj, "dtstart")
and vobj.dtstart.value.strftime("%F%H%M%S")
"dtstart" in comp
and comp['dtstart'].dt.strftime("%F%H%M%S")
> datetime.now().strftime("%F%H%M%S")
),
}
for sort_key in sort_keys:
val = getattr(vobj, sort_key, None)
val = comp.get(sort_key, None)
if val is None:
ret.append(defaults.get(sort_key, "0"))
ret.append(defaults.get(sort_key.lower(), 0))
continue
val = val.value
if hasattr(val, 'dt'):
val = val.dt
elif hasattr(val, 'cats'):
val = cats.join(",")
if hasattr(val, "strftime"):
ret.append(val.strftime("%F%H%M%S"))
else:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_caldav.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,9 @@ def testSearchEvent(self):
all_events = c.search(sort_keys=("summary", "dtstamp"))
assert len(all_events) == 3
assert all_events[0].instance.vevent.summary.value == "Bastille Day Jitsi Party"
all_events = c.search(sort_keys=("SUMMARY", "DTSTAMP"))
assert len(all_events) == 3
assert all_events[0].instance.vevent.summary.value == "Bastille Day Jitsi Party"

def testSearchTodos(self):
self.skip_on_compatibility_flag("read_only")
Expand Down

0 comments on commit 95370cd

Please sign in to comment.