# HG changeset patch # User Paul Boddie # Date 1516466483 -3600 # Node ID 4b15a54aaa6e511738371da8be4f89b681ddeb77 # Parent 67b04224b4d61805bc4cdfe1b6b8799403d08546 Introduced an object method to make a new separate recurrence instance. diff -r 67b04224b4d6 -r 4b15a54aaa6e imiptools/client.py --- a/imiptools/client.py Fri Jan 19 19:26:36 2018 +0100 +++ b/imiptools/client.py Sat Jan 20 17:41:23 2018 +0100 @@ -3,7 +3,7 @@ """ Common calendar client utilities. -Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie +Copyright (C) 2014, 2015, 2016, 2017, 2018 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -867,13 +867,6 @@ if periods: - # For new recurrences, duplicate the core of the object without any - # period information. - - template = self.obj.copy() - template.remove_all(["EXDATE", "RRULE", "RDATE", "DTSTART", "DTEND", - "DURATION"]) - # Process each period, attempting to update existing recurrences or # creating new ones. @@ -885,21 +878,13 @@ obj = self.get_stored_object(self.uid, p.get_recurrenceid()) - # Use the template without an existing recurrence. + # Make a new separate recurrence if necessary. if not obj: - obj = template.copy() # Added methods do not employ a recurrence identifier. - if method != "ADD": - - # Acquire the original recurrence identifier associated with - # this period. This may differ where the start of the period - # has changed. - - dt, attr = p.get_recurrenceid_item() - obj["RECURRENCE-ID"] = [(format_datetime(dt), attr)] + obj = self.obj.make_recurrence(p, method != "ADD") # Update any sequence number if the period has changed from any # stored version. @@ -911,10 +896,10 @@ if main != p: self.update_sequence(obj) - # Set specific recurrence information. + # Set specific recurrence information. - obj.set_datetime("DTSTART", p.get_start()) - obj.set_datetime("DTEND", p.get_end()) + obj.set_datetime("DTSTART", p.get_start()) + obj.set_datetime("DTEND", p.get_end()) objects.append(obj) diff -r 67b04224b4d6 -r 4b15a54aaa6e imiptools/data.py --- a/imiptools/data.py Fri Jan 19 19:26:36 2018 +0100 +++ b/imiptools/data.py Sat Jan 20 17:41:23 2018 +0100 @@ -181,6 +181,34 @@ return map(self.get_recurrence_start_point, recurrenceids) + def make_recurrence(self, period, with_id=True): + + "Return a new recurrence based on the given 'period' in this object." + + obj = self.copy() + + # Remove all temporal information. + + obj.remove_all(["EXDATE", "RRULE", "RDATE", "DTSTART", "DTEND", + "DURATION"]) + + # Set the main period. + + obj.set_datetime("DTSTART", period.get_start()) + obj.set_datetime("DTEND", period.get_end()) + + # Set a recurrence identifier if requested. + + if with_id: + + # Acquire the original recurrence identifier associated with this + # period. This may differ where the start of the period has changed. + + dt, attr = period.get_recurrenceid_item() + obj["RECURRENCE-ID"] = [(format_datetime(dt), attr)] + + return obj + # Structure access. def add(self, obj):