# HG changeset patch # User Paul Boddie # Date 1438536993 -7200 # Node ID 6c23b78ed1551322210d64ceb80a6a5da76eb85a # Parent 14b3142e5870eb506402b7b684f5b2f23c364fa3 Support interpretation and conversion of floating datetimes with explicit zones. diff -r 14b3142e5870 -r 6c23b78ed155 imiptools/dates.py --- a/imiptools/dates.py Sun Aug 02 19:29:16 2015 +0200 +++ b/imiptools/dates.py Sun Aug 02 19:36:33 2015 +0200 @@ -296,24 +296,25 @@ """ if isinstance(dt, datetime): - return dt + return to_timezone(dt, tzid) else: return get_start_of_day(dt, tzid) -def to_utc_datetime(dt, date_tzid=None): +def to_utc_datetime(dt, tzid=None): """ - Return a datetime corresponding to 'dt' in the UTC time zone. If 'date_tzid' - is specified, dates are converted to datetimes using the time zone - information; otherwise, dates remain unconverted. + Return a datetime corresponding to 'dt' in the UTC time zone. If 'tzid' + is specified, dates and floating datetimes are converted to UTC datetimes + using the time zone information; otherwise, such dates and datetimes remain + unconverted. """ if not dt: return None - elif isinstance(dt, datetime): + elif get_datetime_tzid(dt): return to_timezone(dt, "UTC") - elif date_tzid: - return to_timezone(to_datetime(dt, date_tzid), "UTC") + elif tzid: + return to_timezone(to_datetime(dt, tzid), "UTC") else: return dt