1.1 --- a/imiptools/client.py Fri Jan 19 19:26:36 2018 +0100
1.2 +++ b/imiptools/client.py Sat Jan 20 17:41:23 2018 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Common calendar client utilities.
1.6
1.7 -Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2014, 2015, 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -867,13 +867,6 @@
1.13
1.14 if periods:
1.15
1.16 - # For new recurrences, duplicate the core of the object without any
1.17 - # period information.
1.18 -
1.19 - template = self.obj.copy()
1.20 - template.remove_all(["EXDATE", "RRULE", "RDATE", "DTSTART", "DTEND",
1.21 - "DURATION"])
1.22 -
1.23 # Process each period, attempting to update existing recurrences or
1.24 # creating new ones.
1.25
1.26 @@ -885,21 +878,13 @@
1.27
1.28 obj = self.get_stored_object(self.uid, p.get_recurrenceid())
1.29
1.30 - # Use the template without an existing recurrence.
1.31 + # Make a new separate recurrence if necessary.
1.32
1.33 if not obj:
1.34 - obj = template.copy()
1.35
1.36 # Added methods do not employ a recurrence identifier.
1.37
1.38 - if method != "ADD":
1.39 -
1.40 - # Acquire the original recurrence identifier associated with
1.41 - # this period. This may differ where the start of the period
1.42 - # has changed.
1.43 -
1.44 - dt, attr = p.get_recurrenceid_item()
1.45 - obj["RECURRENCE-ID"] = [(format_datetime(dt), attr)]
1.46 + obj = self.obj.make_recurrence(p, method != "ADD")
1.47
1.48 # Update any sequence number if the period has changed from any
1.49 # stored version.
1.50 @@ -911,10 +896,10 @@
1.51 if main != p:
1.52 self.update_sequence(obj)
1.53
1.54 - # Set specific recurrence information.
1.55 + # Set specific recurrence information.
1.56
1.57 - obj.set_datetime("DTSTART", p.get_start())
1.58 - obj.set_datetime("DTEND", p.get_end())
1.59 + obj.set_datetime("DTSTART", p.get_start())
1.60 + obj.set_datetime("DTEND", p.get_end())
1.61
1.62 objects.append(obj)
1.63
2.1 --- a/imiptools/data.py Fri Jan 19 19:26:36 2018 +0100
2.2 +++ b/imiptools/data.py Sat Jan 20 17:41:23 2018 +0100
2.3 @@ -181,6 +181,34 @@
2.4
2.5 return map(self.get_recurrence_start_point, recurrenceids)
2.6
2.7 + def make_recurrence(self, period, with_id=True):
2.8 +
2.9 + "Return a new recurrence based on the given 'period' in this object."
2.10 +
2.11 + obj = self.copy()
2.12 +
2.13 + # Remove all temporal information.
2.14 +
2.15 + obj.remove_all(["EXDATE", "RRULE", "RDATE", "DTSTART", "DTEND",
2.16 + "DURATION"])
2.17 +
2.18 + # Set the main period.
2.19 +
2.20 + obj.set_datetime("DTSTART", period.get_start())
2.21 + obj.set_datetime("DTEND", period.get_end())
2.22 +
2.23 + # Set a recurrence identifier if requested.
2.24 +
2.25 + if with_id:
2.26 +
2.27 + # Acquire the original recurrence identifier associated with this
2.28 + # period. This may differ where the start of the period has changed.
2.29 +
2.30 + dt, attr = period.get_recurrenceid_item()
2.31 + obj["RECURRENCE-ID"] = [(format_datetime(dt), attr)]
2.32 +
2.33 + return obj
2.34 +
2.35 # Structure access.
2.36
2.37 def add(self, obj):