From 7cd01a63d340c254116da1ef9937d30048184dbe Mon Sep 17 00:00:00 2001 From: Kun Huang Date: Sat, 20 Jul 2013 09:52:56 +0800 Subject: [PATCH] Add 'Z' into isoformat for UTC time Based on this http://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators. A isofomt of time need a 'Z' for UTC time zone, or none for local time zone request on GET ///?format=json still output a UTC time without 'Z' fixes bug #1169287 Change-Id: Ib599b5ec8fd223878ec18df7c1ec8d952fc2630a --- swift/container/server.py | 2 ++ test/unit/container/test_server.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/swift/container/server.py b/swift/container/server.py index b1d4d728bc..270dab69b1 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -420,6 +420,7 @@ class ContainerController(object): # python isoformat() doesn't include msecs when zero if len(created_at) < len("1970-01-01T00:00:00.000000"): created_at += ".000000" + created_at += 'Z' content_type, size = self.derive_content_type_metadata( content_type, size) data.append({'last_modified': created_at, 'bytes': size, @@ -434,6 +435,7 @@ class ContainerController(object): # python isoformat() doesn't include msecs when zero if len(created_at) < len("1970-01-01T00:00:00.000000"): created_at += ".000000" + created_at += 'Z' if content_type is None: xml_output.append( '%s' % diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py index d56f0681e2..ab88d8cac5 100644 --- a/test/unit/container/test_server.py +++ b/test/unit/container/test_server.py @@ -738,17 +738,17 @@ class TestContainerController(unittest.TestCase): "hash":"x", "bytes":0, "content_type":"text/plain", - "last_modified":"1970-01-01T00:00:01.000000"}, + "last_modified":"1970-01-01T00:00:01.000000Z"}, {"name":"1", "hash":"x", "bytes":0, "content_type":"text/plain", - "last_modified":"1970-01-01T00:00:01.000000"}, + "last_modified":"1970-01-01T00:00:01.000000Z"}, {"name":"2", "hash":"x", "bytes":0, "content_type":"text/plain", - "last_modified":"1970-01-01T00:00:01.000000"}] + "last_modified":"1970-01-01T00:00:01.000000Z"}] req = Request.blank('/sda1/p/a/jsonc?format=json', environ={'REQUEST_METHOD': 'GET'}) @@ -860,12 +860,12 @@ class TestContainerController(unittest.TestCase): "hash":"x", "bytes":0, "content_type":"text/plain", - "last_modified":"1970-01-01T00:00:01.500000"}, + "last_modified":"1970-01-01T00:00:01.500000Z"}, {"name":"1", "hash":"x", "bytes":0, "content_type":"text/plain", - "last_modified":"1970-01-01T00:00:01.000000"}, ] + "last_modified":"1970-01-01T00:00:01.000000Z"}, ] req = Request.blank('/sda1/p/a/jsonc?format=json', environ={'REQUEST_METHOD': 'GET'}) @@ -894,15 +894,15 @@ class TestContainerController(unittest.TestCase): '' \ '0x0' \ 'text/plain' \ - '1970-01-01T00:00:01.000000' \ + '1970-01-01T00:00:01.000000Z' \ '' \ '1x0' \ 'text/plain' \ - '1970-01-01T00:00:01.000000' \ + '1970-01-01T00:00:01.000000Z' \ '' \ '2x0' \ 'text/plain' \ - '1970-01-01T00:00:01.000000' \ + '1970-01-01T00:00:01.000000Z' \ '' \ '' # tests @@ -1113,9 +1113,9 @@ class TestContainerController(unittest.TestCase): resp = self.controller.GET(req) self.assertEquals(simplejson.loads(resp.body), [{"name":"US/OK", "hash":"x", "bytes":0, "content_type":"text/plain", - "last_modified":"1970-01-01T00:00:01.000000"}, + "last_modified":"1970-01-01T00:00:01.000000Z"}, {"name":"US/TX", "hash":"x", "bytes":0, "content_type":"text/plain", - "last_modified":"1970-01-01T00:00:01.000000"}]) + "last_modified":"1970-01-01T00:00:01.000000Z"}]) def test_GET_insufficient_storage(self): self.controller = container_server.ContainerController(