ics-py / ics-py

Pythonic and easy iCalendar library (rfc5545)

Home Page:http://icspy.readthedocs.org/en/stable/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating Events from 'date's should yield all-day Events

N-Coder opened this issue · comments

I guess these are not really all-day events as they simply start at noon and end in the same instant. Would it be easier to mix different event types in the same Calendar (i.e. all-day, multi-day all-day, no specified end, fixed end or duration, maybe even with/without timezones?) and then thoroughly test that calendar?

Note: We could also infer that an Event should be all-day if its created from dates instead of datetimes, but currently the ensure_datetime here silently sets the time to midnight if its missing and ignores this distinction. Something like the following might fix that but needs further testing.

if (begin is not None or end is not None or duration is not None) and "timespan" in kwargs:
    raise ValueError("can't specify explicit timespan together with any of begin, end or duration")
timespan = kwargs.pop("timespan", EventTimespan(ensure_datetime(begin), ensure_datetime(end), ensure_timedelta(duration)))
if isinstance(begin, date) and not timespan.get_effective_duration().seconds:  # TODO we should also drop microseconds to be able to ignore them here
    timespan = timespan.make_all_day()
super(Event, self).__init__(timespan, summary, *args, **kwargs)

Originally posted by @N-Coder in #325 (comment)