Revert "jsonutils: replace strtime() usage with isoformat()"

This is a wire format change that the projects are not ready for yet (example Nova).

We should do this as part of a major version bump (2.x) with ample time for folks to move up.

Nova review to prepare the Nova code base for this change:
Ib7e60ed94edd1eb409baf8c29c61237d85944787

This reverts commit 5b0827a3df.

Change-Id: Ic4bf047b40c1dad2f8d2bc0afda934e47dba1f9d
This commit is contained in:
Davanum Srinivas (dims) 2015-06-01 19:35:55 +00:00 committed by Davanum Srinivas
parent 986ec5832e
commit 15c82cc902
3 changed files with 4 additions and 10 deletions

View File

@ -57,6 +57,7 @@ else:
from oslo_utils import encodeutils from oslo_utils import encodeutils
from oslo_utils import importutils from oslo_utils import importutils
from oslo_utils import timeutils
import six import six
import six.moves.xmlrpc_client as xmlrpclib import six.moves.xmlrpc_client as xmlrpclib
@ -110,7 +111,7 @@ def to_primitive(value, convert_instances=False, convert_datetime=True,
if isinstance(value, datetime.datetime): if isinstance(value, datetime.datetime):
if convert_datetime: if convert_datetime:
return value.isoformat() return timeutils.strtime(value)
else: else:
return value return value

View File

@ -17,7 +17,6 @@ import collections
import datetime import datetime
import json import json
import iso8601
import mock import mock
import netaddr import netaddr
from oslo_i18n import fixture from oslo_i18n import fixture
@ -136,12 +135,6 @@ class ToPrimitiveTestCase(test_base.BaseTestCase):
self.assertEqual(jsonutils.to_primitive(x), self.assertEqual(jsonutils.to_primitive(x),
'1920-02-03T04:05:06.000007') '1920-02-03T04:05:06.000007')
def test_datetime_timezone(self):
x = datetime.datetime(1920, 2, 3, 4, 5, 6, 7,
tzinfo=iso8601.iso8601.UTC)
self.assertEqual(jsonutils.to_primitive(x),
'1920-02-03T04:05:06.000007+00:00')
def test_datetime_preserve(self): def test_datetime_preserve(self):
x = datetime.datetime(1920, 2, 3, 4, 5, 6, 7) x = datetime.datetime(1920, 2, 3, 4, 5, 6, 7)
self.assertEqual(jsonutils.to_primitive(x, convert_datetime=False), x) self.assertEqual(jsonutils.to_primitive(x, convert_datetime=False), x)
@ -150,7 +143,7 @@ class ToPrimitiveTestCase(test_base.BaseTestCase):
x = xmlrpclib.DateTime() x = xmlrpclib.DateTime()
x.decode("19710203T04:05:06") x.decode("19710203T04:05:06")
self.assertEqual(jsonutils.to_primitive(x), self.assertEqual(jsonutils.to_primitive(x),
'1971-02-03T04:05:06') '1971-02-03T04:05:06.000000')
def test_iter(self): def test_iter(self):
class IterClass(object): class IterClass(object):

View File

@ -173,7 +173,7 @@ class ToPrimitiveTestCase(test_base.BaseTestCase):
x = xmlrpclib.DateTime() x = xmlrpclib.DateTime()
x.decode("19710203T04:05:06") x.decode("19710203T04:05:06")
self.assertEqual(jsonutils.to_primitive(x), self.assertEqual(jsonutils.to_primitive(x),
'1971-02-03T04:05:06') '1971-02-03T04:05:06.000000')
def test_iter(self): def test_iter(self):
class IterClass(object): class IterClass(object):