summaryrefslogtreecommitdiff
path: root/calendar-cli.py
diff options
context:
space:
mode:
authorTobias Brox <t@tobixen.no>2015-06-01 21:37:54 +0200
committerTobias Brox <t@tobixen.no>2015-06-01 21:37:54 +0200
commite1579189384fcf07a455ae2f686f29ea7c63ac38 (patch)
tree43f50ba13e7771e0ec3bf622ad12c9984adfe543 /calendar-cli.py
parent86faaec1207d47bd2280cc3e0b3d082420db3293 (diff)
downloadcalendar-cli-e1579189384fcf07a455ae2f686f29ea7c63ac38.zip
recurring todos should now be supported the way I would like it to work, though this is quite untested ...
Diffstat (limited to 'calendar-cli.py')
-rwxr-xr-xcalendar-cli.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/calendar-cli.py b/calendar-cli.py
index f3dfad3..4338145 100755
--- a/calendar-cli.py
+++ b/calendar-cli.py
@@ -18,6 +18,7 @@ import json
import os
import logging
import sys
+import re
__version__ = "0.11.0-dev"
__author__ = "Tobias Brox"
@@ -563,13 +564,38 @@ def todo_complete(caldav_conn, args):
next = rrule.after(datetime.now())
except TypeError: ## pesky problem with comparition of timestamps with and without tzinfo
next = rrule.after(datetime.now(tz=tzlocal.get_localzone()))
- import pdb; pdb.set_trace()
- ## WORK IN PROGRESS
- ## task.rrule.count - decrease it?
- ## new_task should be a copy of task
- ## set new_task.rrule_id or whatnot
- ## delete new_task.rrule
- ## new_task should be completed, old task should not.
+ if next:
+ import pdb; pdb.set_trace()
+ ## WORK IN PROGRESS
+
+ ## new_task is to be completed and we keep the original task open
+ completed_task = task.copy()
+ remaining_task = task
+
+ ## the remaining task should have recurrence id set to next start time, and range THISANDFUTURE
+ if hasattr(remaining_task.instance.vtodo, 'recurrence_id'):
+ del remaining_task.instance.vtodo.recurrence_id
+ remaining_task.instance.vtodo.add('recurrence-id')
+ remaining_task.instance.vtodo.recurrence_id.value = next ## TODO: should be same type as dtstart (date or datetime)
+ remaining_task.instance.vtodo.dtstart.value = next ## TODO: should be same type as dtstart (date or datetime)
+ remaining_task.instance.vtodo.recurrence_id.params['RANGE'] = [ 'THISANDFUTURE' ]
+ remaining_task.instance.vtodo.rrule
+ remaining_task.save()
+
+ ## the completed task should have recurrence id set to current time
+ ## count in rrule should decrease
+ if hasattr(completed_task.instance.vtodo, 'recurrence_id'):
+ del completed_task.instance.vtodo.recurrence_id
+ completed_task.instance.vtodo.add('recurrence-id')
+ completed_task.instance.vtodo.recurrence_id.value = datetime.now()
+ completed_task.instance.vtodo.dtstart.value = datetime.now()
+ count_search = re.search('COUNT=(\d+)', completed_task.instance.vtodo.rrule.value)
+ if count_search:
+ completed_task.instance.vtodo.rrule.value = re.replace('COUNT=(\d+)', 'COUNT=%d' % int(count_search.group(1))-1)
+ completed_task.complete()
+
+ continue
+
task.complete()