imip-agent

Change of imiptools/dates.py

627:23f998c9dacd
imiptools/dates.py
     1.1 --- a/imiptools/dates.py	Sat Aug 01 01:25:21 2015 +0200
     1.2 +++ b/imiptools/dates.py	Sat Aug 01 01:35:03 2015 +0200
     1.3 @@ -273,6 +273,15 @@
     1.4      else:
     1.5          return None
     1.6  
     1.7 +def get_period_tzid(start, end):
     1.8 +
     1.9 +    "Return the time zone identifier for 'start' and 'end' or None if unknown."
    1.10 +
    1.11 +    if isinstance(start, datetime) or isinstance(end, datetime):
    1.12 +        return get_datetime_tzid(start) or get_datetime_tzid(end)
    1.13 +    else:
    1.14 +        return None
    1.15 +
    1.16  def to_date(dt):
    1.17  
    1.18      "Return the date of 'dt'."
    1.19 @@ -375,8 +384,6 @@
    1.20      else:
    1.21          return {"VALUE" : "DATE"}
    1.22  
    1.23 -    return {}
    1.24 -
    1.25  def get_datetime_item(dt, tzid=None):
    1.26  
    1.27      """
    1.28 @@ -392,11 +399,15 @@
    1.29      attr = get_datetime_attributes(dt, tzid)
    1.30      return value, attr
    1.31  
    1.32 -def get_period_attributes(tzid=None):
    1.33 +def get_period_attributes(start, end, tzid=None):
    1.34  
    1.35 -    "Return attributes for 'tzid'."
    1.36 +    """
    1.37 +    Return attributes for the 'start' and 'end' datetime objects with 'tzid'
    1.38 +    indicating the time zone if not otherwise defined.
    1.39 +    """
    1.40  
    1.41      attr = {"VALUE" : "PERIOD"}
    1.42 +    tzid = get_period_tzid(start, end) or tzid
    1.43      if tzid:
    1.44          attr["TZID"] = tzid
    1.45      return attr
    1.46 @@ -408,17 +419,14 @@
    1.47      'tzid'.
    1.48      """
    1.49  
    1.50 -    start = start and to_timezone(start, tzid)
    1.51 -    end = end and to_timezone(end, tzid)
    1.52 -
    1.53 -    start_value = start and format_datetime(start) or None
    1.54 -    end_value = end and format_datetime(end) or None
    1.55 -
    1.56      if start and end:
    1.57 -        attr = get_period_attributes(tzid)
    1.58 +        attr = get_period_attributes(start, end, tzid)
    1.59 +        start_value = format_datetime(to_timezone(start, attr.get("TZID")))
    1.60 +        end_value = format_datetime(to_timezone(end, attr.get("TZID")))
    1.61          return "%s/%s" % (start_value, end_value), attr
    1.62      elif start:
    1.63          attr = get_datetime_attributes(start, tzid)
    1.64 +        start_value = format_datetime(to_timezone(start, attr.get("TZID")))
    1.65          return start_value, attr
    1.66      else:
    1.67          return None, None
    1.68 @@ -442,7 +450,9 @@
    1.69  
    1.70      """
    1.71      Return 'recurrenceid' in a form suitable for comparison with period start
    1.72 -    dates or datetimes.
    1.73 +    dates or datetimes. The 'recurrenceid' should be an identifier normalised to
    1.74 +    a UTC datetime or employing a date or floating datetime representation where
    1.75 +    no time zone information was originally provided.
    1.76      """
    1.77  
    1.78      return get_datetime(recurrenceid)
    1.79 @@ -452,26 +462,11 @@
    1.80      """
    1.81      Return 'recurrenceid' in a form suitable for comparison with free/busy start
    1.82      datetimes, using 'tzid' to convert recurrence identifiers that are dates.
    1.83 +    The 'recurrenceid' should be an identifier normalised to a UTC datetime or
    1.84 +    employing a date or floating datetime representation where no time zone
    1.85 +    information was originally provided.
    1.86      """
    1.87  
    1.88      return to_utc_datetime(get_datetime(recurrenceid), tzid)
    1.89  
    1.90 -def to_recurrence_start(recurrenceid):
    1.91 -
    1.92 -    """
    1.93 -    Return 'recurrenceid' in a form suitable for use as an unambiguous
    1.94 -    identifier.
    1.95 -    """
    1.96 -
    1.97 -    return format_datetime(get_recurrence_start(recurrenceid))
    1.98 -
    1.99 -def to_recurrence_start_point(recurrenceid, tzid):
   1.100 -
   1.101 -    """
   1.102 -    Return 'recurrenceid' in a form suitable for use as an unambiguous
   1.103 -    identifier, using 'tzid' to convert recurrence identifiers that are dates.
   1.104 -    """
   1.105 -
   1.106 -    return format_datetime(get_recurrence_start_point(recurrenceid, tzid))
   1.107 -
   1.108  # vim: tabstop=4 expandtab shiftwidth=4