From ce3071437d1871f77c4d8573cbe5f4ea8c817650 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Mon, 16 Jul 2012 10:30:25 -0400 Subject: Use strtime() in to_primitive() for datetime objs. This patch updates jsonutils.to_primitive() to use timeutils.strtime() to convert a datimetime object to a string instead of just using str(). This ensures that we can easily convert the string back to a datetime using timeutils.parse_strtime(). Required for the nova blueprint no-db-messaging. Change-Id: I725b333695930e12e2832378102514326fec639c --- openstack/common/jsonutils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'openstack/common/jsonutils.py') diff --git a/openstack/common/jsonutils.py b/openstack/common/jsonutils.py index 11b7e1e..6130a7f 100644 --- a/openstack/common/jsonutils.py +++ b/openstack/common/jsonutils.py @@ -39,6 +39,8 @@ import itertools import json import xmlrpclib +from openstack.common import timeutils + def to_primitive(value, convert_instances=False, level=0): """Convert a complex object into primitives. @@ -101,7 +103,7 @@ def to_primitive(value, convert_instances=False, level=0): level=level) return o elif isinstance(value, datetime.datetime): - return str(value) + return timeutils.strtime(value) elif hasattr(value, 'iteritems'): return to_primitive(dict(value.iteritems()), convert_instances=convert_instances, -- cgit