1.1 --- a/imiptools/dates.py Sat Feb 07 18:33:40 2015 +0100
1.2 +++ b/imiptools/dates.py Sat Feb 07 21:33:20 2015 +0100
1.3 @@ -85,6 +85,20 @@
1.4 else:
1.5 return dt.strftime("%Y%m%d")
1.6
1.7 +def format_time(dt):
1.8 +
1.9 + "Format the time portion of 'dt' as an iCalendar-compatible string."
1.10 +
1.11 + if not dt:
1.12 + return None
1.13 + elif isinstance(dt, datetime):
1.14 + if dt.tzname() == "UTC":
1.15 + return dt.strftime("%H%M%SZ")
1.16 + else:
1.17 + return dt.strftime("%H%M%S")
1.18 + else:
1.19 + return None
1.20 +
1.21 def get_datetime_item(dt, tzid):
1.22
1.23 "Return an iCalendar-compatible string and attributes for 'dt' and 'tzid'."
1.24 @@ -102,7 +116,7 @@
1.25 the 'attr' mapping (if specified) to control the conversion.
1.26 """
1.27
1.28 - if not attr or attr.get("VALUE") in (None, "DATE-TIME"):
1.29 + if len(value) > 9 and (not attr or attr.get("VALUE") in (None, "DATE-TIME")):
1.30 m = match_datetime_icalendar(value)
1.31 if m:
1.32 year, month, day, hour, minute, second = map(m.group, [
1.33 @@ -119,6 +133,8 @@
1.34
1.35 return to_timezone(dt, m.group("utc") and "UTC" or attr and attr.get("TZID") or None)
1.36
1.37 + return None
1.38 +
1.39 # Permit dates even if the VALUE is not set to DATE.
1.40
1.41 if not attr or attr.get("VALUE") in (None, "DATE"):
1.42 @@ -129,6 +145,12 @@
1.43
1.44 return None
1.45
1.46 +def get_date(dt):
1.47 +
1.48 + "Return the date of 'dt'."
1.49 +
1.50 + return date(dt.year, dt.month, dt.day)
1.51 +
1.52 def get_start_of_day(dt, tzid):
1.53
1.54 """