Skip to content

Commit 4c7fa75

Browse files
committed
Merge pull request #181 from tseaver/131-return_dateimtes_w_utc_zone
Fix #131: return datetime w/ UTC zone.
2 parents ddefb77 + 2bef6ff commit 4c7fa75

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

gcloud/datastore/helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ def get_value_from_protobuf(pb):
8282

8383
if pb.value.HasField('timestamp_microseconds_value'):
8484
microseconds = pb.value.timestamp_microseconds_value
85-
return (datetime.utcfromtimestamp(0) +
86-
timedelta(microseconds=microseconds))
85+
naive = (datetime.utcfromtimestamp(0) +
86+
timedelta(microseconds=microseconds))
87+
return naive.replace(tzinfo=pytz.utc)
8788

8889
elif pb.value.HasField('key_value'):
8990
return Key.from_protobuf(pb.value.key_value)

gcloud/datastore/test_helpers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ def test_datetime(self):
100100
utc = datetime.datetime(2014, 9, 16, 10, 19, 32, 4375, pytz.utc)
101101
micros = (calendar.timegm(utc.timetuple()) * 1000000) + 4375
102102
pb = self._makePB('timestamp_microseconds_value', micros)
103-
# self.assertEqual(self._callFUT(pb), utc) XXX
104-
# see https://github.com/GoogleCloudPlatform/gcloud-python/issues/131
105-
self.assertEqual(self._callFUT(pb), naive)
103+
self.assertEqual(self._callFUT(pb), utc)
106104

107105
def test_key(self):
108106
from gcloud.datastore.datastore_v1_pb2 import Property

0 commit comments

Comments
 (0)