imip-agent

Change of imiptools/data.py

620:6338539a488e
imiptools/data.py
     1.1 --- a/imiptools/data.py	Wed Jul 29 18:41:11 2015 +0200
     1.2 +++ b/imiptools/data.py	Thu Jul 30 18:28:43 2015 +0200
     1.3 @@ -92,6 +92,20 @@
     1.4          dt, attr = t
     1.5          return dt
     1.6  
     1.7 +    def set_datetime(self, name, dt, tzid):
     1.8 +
     1.9 +        """
    1.10 +        Set a datetime for property 'name' using 'dt' and 'tzid', returning
    1.11 +        whether an update has occurred.
    1.12 +        """
    1.13 +
    1.14 +        if dt:
    1.15 +            old_value = self.get_value(name)
    1.16 +            self[name] = [get_datetime_item(dt, tzid)]
    1.17 +            return format_datetime(dt) != old_value
    1.18 +
    1.19 +        return False
    1.20 +
    1.21      def get_datetime_item(self, name):
    1.22          return get_datetime_item(self.details, name)
    1.23  
    1.24 @@ -134,8 +148,23 @@
    1.25      # Computed results.
    1.26  
    1.27      def get_periods(self, tzid, end):
    1.28 +
    1.29 +        """
    1.30 +        Return periods defined by this object, employing the given 'tzid' where
    1.31 +        no time zone information is defined, and limiting the collection to a
    1.32 +        window of time with the given 'end'.
    1.33 +        """
    1.34 +
    1.35          return get_periods(self, tzid, end)
    1.36  
    1.37 +    def set_period(self, period):
    1.38 +
    1.39 +        "Set the given 'period' as the main start and end."
    1.40 +
    1.41 +        result = self.set_datetime("DTSTART", period.get_start(), period.start_attr().get("TZID"))
    1.42 +        result = self.set_datetime("DTEND", period.get_end(), period.end_attr().get("TZID")) or result
    1.43 +        return result
    1.44 +
    1.45      def get_tzid(self):
    1.46  
    1.47          """