Closed
Description
Naive datetimes (without timezones) are explicitly coerced to UTC by
'get_protobuf_attribute_and_value':
>>> import calendar
>>> import datetime
>>> import pytz
>>> from gcloud.datastore.helpers import get_protobuf_attribute_and_value
>>> naive = datetime.datetime(2014, 9, 16, 10, 19, 32, 4375) # no zone
>>> utc = datetime.datetime(2014, 9, 16, 10, 19, 32, 4375, pytz.utc)
>>> _, naive_micros = get_protobuf_attribute_and_value(naive)
>>> _, utc_micros = get_protobuf_attribute_and_value(utc)
>>> naive_micros == utc_micros
True
But the datetimes returned by 'get_value_from_protobuf' do not set the UTC
timezone:
>>> from gcloud.datastore.helpers import get_value_from_protobuf
>>> from gcloud.datastore.datastore_v1_pb2 import Property
>>> pb = Property()
>>> pb.value.timestamp_microseconds_value = utc_micros
>>> get_value_from_protobuf(pb) == utc
TypeError: can't compare offset-naive and offset-aware datetimes
>>> get_value_from_protobuf(pb) == naive
True
Leaving them naive when we know they are UTC seens wrong: is there a policy in place which says we will keep in-memory timestamps around as naive-but-UTC-by-convention?