Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ This hook leverages tasklib, so you need to install that too:
pip --user install tasklib
```

You’ll also need to install the [taskw library](https://github.com/ralphbean/taskw/tree/develop), hich allows us to read the configuration file:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/hich/which/


```
git clone -b develop https://github.com/ralphbean/taskw.git
cp -r taskw/taskw ~/.local/lib/python2.7/site-packages/
```

Configuration
-------------

Edit both scripts and set ```LOCAL_TZ``` to your timezone and your desired
local ```DEFAULT_TIME```. For EST, default task date time of 21:30, it should look
as follows::
Configure the timezone and default time with ```task config```:

```
LOCALTZ = pytz.timezone('EST') # Your timezone
DEFAULT_TIME = time(21,30,0) # Your wanted default time
task config default.time 22:00
task config default.timezone Europe/Madrid

```

Example of usage
Expand Down
34 changes: 29 additions & 5 deletions pirate_add_default_time.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
#!/usr/bin/python
from datetime import time
from tasklib.task import Task, local_zone
from datetime import time, datetime, timedelta
from taskw import TaskWarrior
from pytz import timezone, utc

DEFAULT_TIME = time(22,0,0) # Your wanted default time
CONFIG = TaskWarrior.load_config()
if 'dst' in CONFIG['default']:
if CONFIG['default']['dst'].lower() in ['true', '1', 'yes']:
dst = True
else:
dst = False

if 'timezone' in CONFIG['default']:
DEFAULT_ZONE = timezone(CONFIG['default']['timezone'])
else:
DEFAULT_ZONE = utc

if 'time' in CONFIG["default"]:
DEFAULT_TIME = datetime.strptime(CONFIG['default']['time'], u'%H:%M').time()
else:
DEFAULT_TIME = time(0, 0, 0, 0, DEFAULT_ZONE)

def is_local_midnight(timestamp):
return timestamp.astimezone(local_zone).time() == time(0,0,0)
tmp = utc.localize(timestamp).astimezone(DEFAULT_ZONE)
return tmp.time() == time(0, 0, 0)

def set_default_time(timestamp):
return timestamp.astimezone(local_zone).replace(
utcoffset = DEFAULT_ZONE.utcoffset(timestamp, is_dst=dst).days * 24 + DEFAULT_ZONE.utcoffset(timestamp, is_dst=dst).seconds / 3600

tmp = timestamp.replace(
hour=DEFAULT_TIME.hour,
minute=DEFAULT_TIME.minute,
second=DEFAULT_TIME.second,
)

if utcoffset > 0:
tmp += timedelta(days=1)

return DEFAULT_ZONE.localize(tmp).astimezone(utc)

def hook_default_time(task):
if task['due'] and is_local_midnight(task['due']):
task['due'] = set_default_time(task['due'])
Expand Down