]> git.madduck.net Git - etc/taskwarrior.git/blob - on-add-shift-all-recurrence

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Added Licence
[etc/taskwarrior.git] / on-add-shift-all-recurrence
1 #!/usr/bin/python
2
3 import sys
4 from tasklib.task import Task, TaskWarrior
5
6 time_attributes = ('wait', 'until', 'scheduled')
7
8 def is_new_local_recurrence_child_task(task):
9     # Do not affect tasks not spun by recurrence
10     if not task['parent']:
11         return False
12
13     # Newly created recurrence tasks actually have
14     # modified field copied from the parent, thus
15     # older than entry field (until their ID is generated)
16     if (task['modified'] - task['entry']).total_seconds() < 0:
17         return True
18
19 task = Task.from_input()
20 tw = TaskWarrior()
21
22 if is_new_local_recurrence_child_task(task):
23     parent = tw.tasks.get(uuid=task['parent'])
24     parent_due_shift = task['due'] - parent['due']
25     for attr in time_attributes:
26         if parent[attr]:
27             task[attr] = parent[attr] + parent_due_shift
28
29 print task.export_data()