From 2bef6ff1c824f3f5fedf20ea889cdcba9db9920e Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Wed, 24 Sep 2014 17:05:07 -0400 Subject: [PATCH] Fix #131: return datetime w/ UTC zone. --- gcloud/datastore/helpers.py | 5 +++-- gcloud/datastore/test_helpers.py | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/gcloud/datastore/helpers.py b/gcloud/datastore/helpers.py index bde6cbafac66..640a5b89065a 100644 --- a/gcloud/datastore/helpers.py +++ b/gcloud/datastore/helpers.py @@ -78,8 +78,9 @@ def get_value_from_protobuf(pb): if pb.value.HasField('timestamp_microseconds_value'): microseconds = pb.value.timestamp_microseconds_value - return (datetime.utcfromtimestamp(0) + - timedelta(microseconds=microseconds)) + naive = (datetime.utcfromtimestamp(0) + + timedelta(microseconds=microseconds)) + return naive.replace(tzinfo=pytz.utc) elif pb.value.HasField('key_value'): return Key.from_protobuf(pb.value.key_value) diff --git a/gcloud/datastore/test_helpers.py b/gcloud/datastore/test_helpers.py index d00e1efea7a8..8fe5abef5f75 100644 --- a/gcloud/datastore/test_helpers.py +++ b/gcloud/datastore/test_helpers.py @@ -92,9 +92,7 @@ def test_datetime(self): utc = datetime.datetime(2014, 9, 16, 10, 19, 32, 4375, pytz.utc) micros = (calendar.timegm(utc.timetuple()) * 1000000) + 4375 pb = self._makePB('timestamp_microseconds_value', micros) - # self.assertEqual(self._callFUT(pb), utc) XXX - # see https://github.com/GoogleCloudPlatform/gcloud-python/issues/131 - self.assertEqual(self._callFUT(pb), naive) + self.assertEqual(self._callFUT(pb), utc) def test_key(self): from gcloud.datastore.datastore_v1_pb2 import Property