imip-agent

Change of imiptools/period.py

620:6338539a488e
imiptools/period.py
     1.1 --- a/imiptools/period.py	Wed Jul 29 18:41:11 2015 +0200
     1.2 +++ b/imiptools/period.py	Thu Jul 30 18:28:43 2015 +0200
     1.3 @@ -37,6 +37,9 @@
     1.4          """
     1.5          Initialise a period with the given 'start' and 'end', having a
     1.6          contextual 'tzid', if specified, and an indicated 'origin'.
     1.7 +
     1.8 +        All metadata from the start and end points are derived from the supplied
     1.9 +        dates/datetimes.
    1.10          """
    1.11  
    1.12          self.start = isinstance(start, date) and start or get_datetime(start)
    1.13 @@ -80,13 +83,19 @@
    1.14          return self.end
    1.15  
    1.16      def get_tzid(self):
    1.17 -        return self.tzid
    1.18 +        return get_tzid(self.get_start_attr(), self.get_end_attr()) or self.tzid
    1.19 +
    1.20 +    def get_start_attr(self):
    1.21 +        return get_datetime_attributes(self.start, self.tzid)
    1.22 +
    1.23 +    def get_end_attr(self):
    1.24 +        return get_datetime_attributes(self.end, self.tzid)
    1.25  
    1.26      def get_start_item(self):
    1.27 -        return self.start, get_datetime_attributes(self.start, self.get_tzid())
    1.28 +        return self.get_start(), self.get_start_attr()
    1.29  
    1.30      def get_end_item(self):
    1.31 -        return self.end, get_datetime_attributes(self.end, self.get_tzid())
    1.32 +        return self.get_end(), self.get_end_attr()
    1.33  
    1.34      def get_start_point(self):
    1.35          return to_utc_datetime(self.get_start(), self.get_tzid())
    1.36 @@ -152,21 +161,21 @@
    1.37  
    1.38  class RecurringPeriod(Period):
    1.39      
    1.40 -    "A period with iCalendar attribute and origin information from the object."
    1.41 +    """
    1.42 +    A period with iCalendar metadata attributes and origin information from an
    1.43 +    object.
    1.44 +    """
    1.45      
    1.46      def __init__(self, start, end, tzid=None, origin=None, start_attr=None, end_attr=None):
    1.47          Period.__init__(self, start, end, tzid, origin)
    1.48          self.start_attr = start_attr
    1.49          self.end_attr = end_attr
    1.50  
    1.51 -    def get_start_item(self):
    1.52 -        return self.get_start(), self.start_attr
    1.53 +    def get_start_attr(self):
    1.54 +        return self.start_attr
    1.55  
    1.56 -    def get_end_item(self):
    1.57 -        return self.get_end(), self.end_attr
    1.58 -
    1.59 -    def get_tzid(self):
    1.60 -        return get_tzid(self.start_attr, self.end_attr) or self.tzid
    1.61 +    def get_end_attr(self):
    1.62 +        return self.end_attr
    1.63  
    1.64      def as_tuple(self):
    1.65          return self.start, self.end, self.tzid, self.origin, self.start_attr, self.end_attr