# HG changeset patch # User Paul Boddie # Date 1422988268 -3600 # Node ID d2824e976174bd0d0db80ba08276a324ff9662a8 # Parent 4fbb7ffae1ecf54271c9eb78dcaa16d64a316094 Incorporate selected time periods into selected days, merging adjacent days when creating new events. diff -r 4fbb7ffae1ec -r d2824e976174 imip_manager.py --- a/imip_manager.py Tue Feb 03 19:29:38 2015 +0100 +++ b/imip_manager.py Tue Feb 03 19:31:08 2015 +0100 @@ -35,7 +35,7 @@ Object, to_part from imiptools.dates import format_datetime, get_datetime, get_datetime_item, \ get_end_of_day, get_start_of_day, get_start_of_next_day, \ - get_timestamp, ends_on_same_day, to_timezone + get_timestamp, ends_on_same_day, next_date, to_timezone from imiptools.mail import Messenger from imiptools.period import add_day_start_points, add_slots, convert_periods, \ get_freebusy_details, \ @@ -378,12 +378,29 @@ for slot in slots: start, end = slot.split("-") + end = end or next_date(start) + if last: - if start == last[1]: - last = last[0], end + last_start, last_end = last + + # Merge adjacent dates and datetimes. + + if start == last_end: + last = last_start, end continue + + # Handle datetimes within dates. + # Datetime periods are within single days and are therefore + # discarded. + + elif start.startswith(last_start): + continue + + # Add separate dates and datetimes. + else: coalesced.append(last) + last = start, end if last: diff -r 4fbb7ffae1ec -r d2824e976174 imiptools/dates.py --- a/imiptools/dates.py Tue Feb 03 19:29:38 2015 +0100 +++ b/imiptools/dates.py Tue Feb 03 19:31:08 2015 +0100 @@ -197,4 +197,13 @@ return format_datetime(to_timezone(datetime.utcnow(), "UTC")) +def next_date(s): + + """ + Return an iCalendar-compatible string indicating the next date after the one + provided by 's'. + """ + + return format_datetime(get_datetime(s) + timedelta(1)) + # vim: tabstop=4 expandtab shiftwidth=4