diff options
author | Tobias Brox <tobias@redpill-linpro.com> | 2017-04-01 20:11:16 +0200 |
---|---|---|
committer | Tobias Brox <tobias@redpill-linpro.com> | 2017-04-01 20:11:16 +0200 |
commit | ccfdd7315797a99f82a7c616c42c9313b2e556c6 (patch) | |
tree | f545601676d1a4a5de8e35a9b4fec8c0ead34eef | |
parent | 451bc9007f39e208ec3d2b78566be5b7b30eb540 (diff) | |
download | calendar-cli-ccfdd7315797a99f82a7c616c42c9313b2e556c6.zip |
yet some more bugfixes wrg date/datetime incompatibility issues
-rwxr-xr-x | calendar-cli.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/calendar-cli.py b/calendar-cli.py index 251ff7e..7edd613 100755 --- a/calendar-cli.py +++ b/calendar-cli.py @@ -47,6 +47,14 @@ __status__ = "Development" __product__ = "calendar-cli" __description__ = "high-level cli against caldav servers" +def _date(ts): + """ + helper function to get a date out of a Date or Datetime object. + """ + if hasattr(ts, 'date'): + return ts.date() + return ts + def _force_datetime(t, args): """ date objects cannot be compared with timestamp objects, neither in python2 nor python3. Silly. @@ -284,8 +292,8 @@ def calendar_add(caldav_conn, args): duration = int(event_spec[1][:-1]) dtstart = dateutil.parser.parse(event_spec[0]) dtend = dtstart + timedelta(days=duration) - event.add('dtstart', dtstart.date()) - event.add('dtend', dtend.date()) + event.add('dtstart', _date(dtstart.date)) + event.add('dtend', _date(dtend.date)) else: event.add('dtstart', dtstart) ## TODO: handle duration and end-time as options. default 3600s by now. @@ -544,7 +552,7 @@ def todo_postpone(caldav_conn, args): else: new_ts = dateutil.parser.parse(args.until) if not new_ts.time(): - new_ts = new_ts.date() + new_ts = _date(new_ts) tasks = todo_select(caldav_conn, args) for task in tasks: @@ -562,12 +570,12 @@ def todo_postpone(caldav_conn, args): if type(task.instance.vtodo.dtstart.value) != type(task.instance.vtodo.due.value): ## RFC states they must be of the same type if isinstance(task.instance.vtodo.dtstart.value, date): - task.instance.vtodo.due.value = task.instance.vtodo.due.value.date() + task.instance.vtodo.due.value = _date(task.instance.vtodo.due.value) else: d = task.instance.vtodo.due.value task.instance.vtodo.due.value = datetime(d.year, d.month, d.day) ## RFC also states that due cannot be before dtstart (and that makes sense) - if task.instance.vtodo.dtstart.value > task.instance.vtodo.due.value: + if _force_datetime(task.instance.vtodo.dtstart.value, args) > _force_datetime(task.instance.vtodo.due.value, args): task.instance.vtodo.due.value = task.instance.vtodo.dtstart.value task.save() |