1.1 --- a/imiptools/data.py Tue Apr 07 18:57:35 2015 +0200
1.2 +++ b/imiptools/data.py Tue Apr 07 22:06:39 2015 +0200
1.3 @@ -58,8 +58,8 @@
1.4 def get_value(self, name):
1.5 return get_value(self.details, name)
1.6
1.7 - def get_utc_datetime(self, name):
1.8 - return get_utc_datetime(self.details, name)
1.9 + def get_utc_datetime(self, name, date_tzid=None):
1.10 + return get_utc_datetime(self.details, name, date_tzid)
1.11
1.12 def get_date_values(self, name, tzid=None):
1.13 items = get_date_value_items(self.details, name, tzid)
1.14 @@ -300,13 +300,19 @@
1.15 else:
1.16 return None
1.17
1.18 -def get_utc_datetime(d, name):
1.19 +def get_utc_datetime(d, name, date_tzid=None):
1.20 +
1.21 + """
1.22 + Return the value provided by 'd' for 'name' as a datetime in the UTC zone
1.23 + or as a date, converting any date to a datetime if 'date_tzid' is specified.
1.24 + """
1.25 +
1.26 t = get_datetime_item(d, name)
1.27 if not t:
1.28 return None
1.29 else:
1.30 dt, attr = t
1.31 - return to_utc_datetime(dt)
1.32 + return to_utc_datetime(dt, date_tzid)
1.33
1.34 def get_datetime_item(d, name):
1.35 t = get_item(d, name)
2.1 --- a/imiptools/dates.py Tue Apr 07 18:57:35 2015 +0200
2.2 +++ b/imiptools/dates.py Tue Apr 07 22:06:39 2015 +0200
2.3 @@ -58,14 +58,20 @@
2.4 match_datetime_icalendar = re.compile(datetime_icalendar_regexp_str, re.UNICODE).match
2.5 match_duration_icalendar = re.compile(duration_icalendar_regexp_str, re.UNICODE).match
2.6
2.7 -def to_utc_datetime(dt):
2.8 +def to_utc_datetime(dt, date_tzid=None):
2.9
2.10 - "Return a datetime corresponding to 'dt' in the UTC time zone."
2.11 + """
2.12 + Return a datetime corresponding to 'dt' in the UTC time zone. If 'date_tzid'
2.13 + is specified, dates are converted to datetimes using the time zone
2.14 + information; otherwise, dates remain unconverted.
2.15 + """
2.16
2.17 if not dt:
2.18 return None
2.19 elif isinstance(dt, datetime):
2.20 return to_timezone(dt, "UTC")
2.21 + elif date_tzid:
2.22 + return to_timezone(to_datetime(dt, date_tzid), "UTC")
2.23 else:
2.24 return dt
2.25
2.26 @@ -380,21 +386,17 @@
2.27 end point defined in UTC.
2.28 """
2.29
2.30 - start = to_utc_datetime_only(start, tzid)
2.31 - end = to_utc_datetime_only(end, tzid)
2.32 + start = to_utc_datetime(start, tzid)
2.33 + end = to_utc_datetime(end, tzid)
2.34 return start, end
2.35
2.36 -def to_utc_datetime_only(dt, tzid):
2.37 +def to_recurrence_start(recurrenceid, tzid):
2.38
2.39 """
2.40 - Return the datetime 'dt' as a point in time in the UTC time zone, given the
2.41 - 'tzid' defined for the datetime. Where 'dt' is a date, the start of the
2.42 - indicated day is returned, defined in UTC.
2.43 + Return 'recurrenceid' in a form suitable for comparison with free/busy start
2.44 + datetimes, using 'tzid' to convert recurrence identifiers that are dates.
2.45 """
2.46
2.47 - if not isinstance(dt, datetime):
2.48 - return to_timezone(get_start_of_day(dt, tzid), "UTC")
2.49 - else:
2.50 - return to_timezone(dt, "UTC")
2.51 + return format_datetime(to_utc_datetime(get_datetime(recurrenceid), tzid))
2.52
2.53 # vim: tabstop=4 expandtab shiftwidth=4