summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Brox <tobias@redpill-linpro.com>2020-06-06 19:01:12 +0200
committerTobias Brox <tobias@redpill-linpro.com>2020-06-06 19:01:18 +0200
commitbb6d7221ce061e040176c903678a9bfe41247b6f (patch)
treeef0687e8af3c5f9865b94e3c53b557fb02356e54
parente402c027fbf70778129d32ac2b7f66e764ede173 (diff)
downloadcalendar-cli-bb6d7221ce061e040176c903678a9bfe41247b6f.zip
when creating an event by dates only, it should implicitly be treated as whole day event
resolves https://github.com/tobixen/calendar-cli/issues/49
-rwxr-xr-xcalendar-cli.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/calendar-cli.py b/calendar-cli.py
index e62d44e..9ad4bc4 100755
--- a/calendar-cli.py
+++ b/calendar-cli.py
@@ -23,6 +23,7 @@ import pytz
import tzlocal
import time
from datetime import datetime, timedelta, date
+from datetime import time as time_
import dateutil.parser
from dateutil.rrule import rrulestr
from icalendar import Calendar,Event,Todo,Journal,Alarm
@@ -343,10 +344,15 @@ def calendar_add(caldav_conn, args):
## TODO: error handling
event_duration_secs = int(event_duration[:-1]) * time_units[event_duration[-1:]]
dtstart = dateutil.parser.parse(event_spec[0])
- if args.whole_day:
- if event_spec[1][-1:] != 'd':
+ if (args.whole_day or
+ (event_duration_secs % (60*60*24) == 0 and
+ dtstart.time() == time_(0,0))):
+
+ ## allowing 1 second off due to leap seconds
+ if (event_duration_secs+1) % (60*60*24) > 2:
raise ValueError('Duration of whole-day event must be multiple of 1d')
- duration = int(event_spec[1][:-1])
+
+ duration = event_duration_secs//60//60//24
dtend = dtstart + timedelta(days=duration)
event.add('dtstart', _date(dtstart.date()))
event.add('dtend', _date(dtend.date()))