summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md10
-rwxr-xr-xcalendar-cli.py25
2 files changed, 29 insertions, 6 deletions
diff --git a/README.md b/README.md
index 379e29a..bcb4117 100644
--- a/README.md
+++ b/README.md
@@ -55,20 +55,20 @@ not be up-to-date and may contain features not implemented yet.
### Event time specification
-Supported in v0.06:
+Supported in v0.9:
* anything recognized by dateutil.parser.parse()
+* An iso time stamp, followed with the duration, using either + or space as separator. Duration is a number postfixed by s for seconds, m for minutes, h for hours, d for days, w for weeks and y for years (i.e. 2013-09-10T13:37+30d)
All of those would eventually be supported in future versions if it's not too difficult to achieve:
-* An iso time stamp, followed with the duration, using either + or space as separator. Duration is a number postfixed by s for seconds, m for minutes, h for hours, d for days, w for weeks and y for years (i.e. 2013-09-10T13:37+30d)
* Two ISO timestamps separated by a dash (-)
* ISO dates without times (default duration will be one day, for two dates full days up to and including the end date is counted)
* "tomorrow" instead of an ISO date
* weekday instead of an ISO date
* clock time without the date; event will be assumed to start within 24 hours.
-Alternatively, endtime or duration can be given through options (not supported as of 0.06. All events are considered to be one hour long).
+Alternatively, endtime or duration can be given through options (not supported as of 0.9)
Configuration file
------------------
@@ -121,10 +121,12 @@ Changelog
* 2014-03-14: version 0.6 - now agenda works quite smooth. I think this is becoming a useful tool.
* 2015-02-15: version 0.7 - supports deletion of events, alternative templates for the event output and a small testing script
* 2015-03-30: version 0.8 - has a interactive configuration mode for those not feeling comfortable with hand-crafting the config in json syntax
+* 2015-03-30: version 0.9 - now it's possible to set a duration when adding events to the calendar.
Roadmap
-------
-* Allow specification of event duration when adding events to calendar
+* Allow pulling out an agenda for all calendars at once (though, with the current design it's so much easier to do it through a bash loop rather than in the python code, so this is postponed for a while)
+* Allow specification of event duration and/or event end time through options
* CLI-interface for creating ical todo events
* Fix easy-to-use symlinks (or alternatively wrapper scripts)
* Make some nosetests
diff --git a/calendar-cli.py b/calendar-cli.py
index e1ad1ba..ca56dba 100755
--- a/calendar-cli.py
+++ b/calendar-cli.py
@@ -183,10 +183,31 @@ def calendar_add(caldav_conn, args):
event = Event()
## TODO: timezone
## read timestamps from arguments
- dtstart = dateutil.parser.parse(args.event_time)
+ time_units = {
+ 's': 1, 'm': 60, 'h': 3600,
+ 'd': 86400, 'w': 604800
+ }
+ event_spec = args.event_time.split('+')
+ if len(event_spec)>3:
+ raise ValueError('Invalid event time "%s" - can max contain 2 plus-signs' % event_time)
+ elif len(event_spec)==3:
+ event_time = '%s+%s' % tuple(event_spec[0:2])
+ event_duration = event_spec[2]
+ elif len(event_spec)==2 and not event_spec[1][-1:] in time_units:
+ event_time = '%s+%s' % tuple(event_spec[0:2])
+ event_duration = '1h'
+ elif len(event_spec)==2:
+ event_time = '%s' % event_spec[0]
+ event_duration = event_spec[1]
+ else:
+ event_time = event_spec[0]
+ event_duration = '1h'
+ ## TODO: error handling
+ event_duration_secs = int(event_duration[:-1]) * time_units[event_duration[-1:]]
+ dtstart = dateutil.parser.parse(event_spec[0])
event.add('dtstart', dtstart)
## TODO: handle duration and end-time as options. default 3600s by now.
- event.add('dtend', dtstart + timedelta(0,3600))
+ event.add('dtend', dtstart + timedelta(0,event_duration_secs))
## not really correct, and it breaks i.e. with google calendar
#event.add('dtstamp', datetime.now())
## maybe we should generate some uid?