timeutils parse_isotime adds tzinfo to ISO strings with no timezone

Bug #1638124 reported by Mario Villaplana
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.utils
Confirmed
Medium
Unassigned

Bug Description

It appears as though timeutils.parse_isotime has some undocumented behavior where timezone-aware datetime objects are returned from ISO 8601 strings that don't specify the timezone.

Observed with oslo_utils 3.17.0, python 2.7.12+:

>>> import datetime
>>> from oslo_utils import timeutils
>>> now_no_tz = datetime.datetime.now()
>>> print(now_no_tz)
2016-10-31 20:27:57.846308
>>> print(now_no_tz.tzinfo)
None
>>> now_iso = now_no_tz.isoformat()
>>> print(now_iso)
2016-10-31T20:27:57.846308
>>> timeutils.parse_isotime(now_iso)
datetime.datetime(2016, 10, 31, 20, 27, 57, 846308, tzinfo=<iso8601.Utc>)
>>> now_no_tz
datetime.datetime(2016, 10, 31, 20, 27, 57, 846308)

This is not compliant with ISO8601, which indicates that a "Z" must follow the datetime string if the timezone is UTC. Otherwise, local time should be assumed. [0]

This behavior should probably be corrected or documented.

[0] https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators

Ben Nemec (bnemec)
Changed in oslo.utils:
status: New → Confirmed
importance: Undecided → Medium
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.