timeutils parse_isotime adds tzinfo to ISO strings with no timezone

Bug #1638124 reported by Mario Villaplana on 2016-10-31
This bug affects 1 person
Affects Status Importance Assigned to Milestone

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)
>>> now_iso = now_no_tz.isoformat()
>>> print(now_iso)
>>> 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) on 2018-04-06
Changed in oslo.utils:
status: New → Confirmed
importance: Undecided → Medium
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers