1.1 --- a/imiptools/dates.py Tue Feb 03 18:44:48 2015 +0100
1.2 +++ b/imiptools/dates.py Tue Feb 03 19:29:38 2015 +0100
1.3 @@ -36,6 +36,9 @@
1.4 match_datetime_icalendar = re.compile(datetime_icalendar_regexp_str, re.UNICODE).match
1.5
1.6 def to_utc_datetime(dt):
1.7 +
1.8 + "Return a datetime corresponding to 'dt' in the UTC time zone."
1.9 +
1.10 if not dt:
1.11 return None
1.12 elif isinstance(dt, datetime):
1.13 @@ -44,6 +47,12 @@
1.14 return dt
1.15
1.16 def to_timezone(dt, name):
1.17 +
1.18 + """
1.19 + Return a datetime corresponding to 'dt' in the time regime having the given
1.20 + 'name'.
1.21 + """
1.22 +
1.23 try:
1.24 tz = name and timezone(name) or None
1.25 except UnknownTimeZoneError:
1.26 @@ -51,6 +60,9 @@
1.27 return to_tz(dt, tz)
1.28
1.29 def to_tz(dt, tz):
1.30 +
1.31 + "Return a datetime corresponding to 'dt' employing the pytz.timezone 'tz'."
1.32 +
1.33 if tz is not None and isinstance(dt, datetime):
1.34 if not dt.tzinfo:
1.35 return tz.localize(dt)
1.36 @@ -60,6 +72,9 @@
1.37 return dt
1.38
1.39 def format_datetime(dt):
1.40 +
1.41 + "Format 'dt' as an iCalendar-compatible string."
1.42 +
1.43 if not dt:
1.44 return None
1.45 elif isinstance(dt, datetime):
1.46 @@ -71,6 +86,9 @@
1.47 return dt.strftime("%Y%m%d")
1.48
1.49 def get_datetime_item(dt):
1.50 +
1.51 + "Return an iCalendar-compatible string and attributes for 'dt'."
1.52 +
1.53 if not dt:
1.54 return None, None
1.55 value = format_datetime(dt)
1.56 @@ -174,6 +192,9 @@
1.57 )
1.58
1.59 def get_timestamp():
1.60 +
1.61 + "Return the current time as an iCalendar-compatible string."
1.62 +
1.63 return format_datetime(to_timezone(datetime.utcnow(), "UTC"))
1.64
1.65 # vim: tabstop=4 expandtab shiftwidth=4