Skip to content

Commit

Permalink
Merge pull request #181 from tseaver/131-return_dateimtes_w_utc_zone
Browse files Browse the repository at this point in the history
Fix #131:  return datetime w/ UTC zone.
  • Loading branch information
silvolu committed Sep 26, 2014
2 parents ddefb77 + 2bef6ff commit 4c7fa75
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 3 additions & 2 deletions gcloud/datastore/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,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)
Expand Down
4 changes: 1 addition & 3 deletions gcloud/datastore/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,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
Expand Down

0 comments on commit 4c7fa75

Please sign in to comment.