From f0c9b20e0fd512e4eaa3f041a02afd80b871fe75 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sat, 2 Dec 2017 11:11:23 -0600 Subject: [PATCH] Handle UTC+00:00 in datetime strings In some cases, the following: datetime.datetime.now(tz=iso8601.iso8601.UTC).tzinfo.tzname() returns: 'UTC+00:00' rather than: 'UTC' resulting in strings that look like: 2013-03-04T12:00:01.000000UTC+00:00 That is just flatly invalid. The code here accounts for a tzname of "UTC" and normalizes to to being a trailing Z as-per the ISO 8601 spec, but it does not account for UTC+00:00. Add support for that so that we don't produce invalid date strings. Most of this can be avoided by replacing use of this function with the isoformat method of datetime instead. datetime.datetime.now(tz=iso8601.iso8601.UTC).isoformat() Produces 2013-03-04T12:00:01.000000+00:00 Which while different from 2013-03-04T12:00:01.000000Z is still a valid iso8601 string. Change-Id: I52ca7561abee158285c2c98ba63d84c62e12360f --- keystoneclient/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keystoneclient/utils.py b/keystoneclient/utils.py index 67609e14c..d71974b55 100644 --- a/keystoneclient/utils.py +++ b/keystoneclient/utils.py @@ -114,7 +114,7 @@ def isotime(at=None, subsecond=False): if not subsecond else _ISO8601_TIME_FORMAT_SUBSECOND) tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC' - st += ('Z' if tz == 'UTC' else tz) + st += ('Z' if (tz == 'UTC' or tz == 'UTC+00:00') else tz) return st