You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DISCUSSION: Should deserialized timestamps have a timezone? #279
It's not immediately clear how we should support this.
The fact that we support datetime.datetime objects with timezones makes the seralize/deserialize operation potentially a function other than the identity.
As a point of reference, NDB supports datetime but doesn't allow any timezone set and assumes utc. This somewhat solves the problem because it only allows offset-naive datetimes.
We could avoid throwing away the good work by putting the offset -> naive conversion into datastore.helpers or by documenting the process in a place people will see.
This solves equality within the datetime.datetime type but we need a Property abstraction to map the difference between time.time, datetime.date and datetime.datetime.
When marshalling naive datetime values to a protobuf value, we already convert them to microseconds (silently) as though they were explicitly UTC. When marshalling zoned datetime values, we first convert to UTC, and then compute the timestamp as microsecons.
The real question is what we should do when unmarshalling a microsecond timestamp from a protobuf: we know it must be UTC, so #181 explicitly adds the UTC zone to it before setting it into the entity dict (rather than leaving it ambiguously naive).
While we could marshall a 'datetime.date' to a timestamp (assuming midnight UTC), there is no way to unmarshall a microsecond timestamp as anything other than a 'datetime.datetime' instance. Given that it would be confusing to marshal a as one type but unmarshall another, I'm not sure we should support passing in 'datetime.date' (principle of least surprise).
Activity
Remove notes about datetime.date objects and timezone matching.
Remove notes about datetime.date objects and timezone matching.
Remove notes about datetime.date objects and timezone matching.
Remove notes about datetime.date objects and timezone matching.
Remove notes about datetime.date objects and timezone matching.
Remove notes about datetime.date objects and timezone matching.
Remove notes about datetime.date objects and timezone matching.
Remove notes about datetime.date objects and timezone matching.
Remove notes about datetime.date objects and timezone matching.
pcostell commentedon Oct 27, 2014
As a point of reference, NDB supports datetime but doesn't allow any timezone set and assumes utc. This somewhat solves the problem because it only allows offset-naive datetimes.
dhermes commentedon Oct 27, 2014
I am in favor of that approach.
We could avoid throwing away the good work by putting the offset -> naive conversion into
datastore.helpersor by documenting the process in a place people will see.This solves equality within the
datetime.datetimetype but we need aPropertyabstraction to map the difference betweentime.time,datetime.dateanddatetime.datetime.Remove notes about datetime.date objects and timezone matching.
tseaver commentedon Oct 27, 2014
When marshalling naive datetime values to a protobuf value, we already convert them to microseconds (silently) as though they were explicitly UTC. When marshalling zoned datetime values, we first convert to UTC, and then compute the timestamp as microsecons.
The real question is what we should do when unmarshalling a microsecond timestamp from a protobuf: we know it must be UTC, so #181 explicitly adds the UTC zone to it before setting it into the entity dict (rather than leaving it ambiguously naive).
While we could marshall a 'datetime.date' to a timestamp (assuming midnight UTC), there is no way to unmarshall a microsecond timestamp as anything other than a 'datetime.datetime' instance. Given that it would be confusing to marshal a as one type but unmarshall another, I'm not sure we should support passing in 'datetime.date' (principle of least surprise).
Remove notes about datetime.date objects and timezone matching.
dhermes commentedon Oct 27, 2014
@tseaver I totally agree. This is too low-level to provide the needed information (i.e. an underlying type) as is done in some higher level libraries:
https://cloud.google.com/appengine/docs/python/ndb/properties#Date_and_Time
However, by requiring naive timestamps are passed in, we can at least guarantee the marshall / unmarshall operations are true inverse functions.
That's why I suggested decoupling the tz -> naive part into it's own helper method.
44 remaining items
chore: Update gapic-generator-python to v1.16.1 (#279)
chore(python): bump idna from 3.4 to 3.7 in .kokoro (#279)
fix function signature for streaming rpc (#279)
chore: Update many dependencies (#279)
chore(python): update dependencies in /.kokoro (#279)
chore(main): release 2.5.1 (#279)
chore(python): Use latest python runtime in prerelease_deps session (#…
fix: Escape html special characters in `hocr_document_template.xml.j2` (
fix: fix missing __ne__ methods (#279)
build: update windows build script to use trimmed python version (#279)
feat: add support for Python 3.10 (#279)
dbapi: make Connection.close invoke rollback, guards for already closed
chore(deps): update dependency importlib-resources to v5.10.0 (#279)
chore: release 1.31.2 (#279)
build: update windows build script to use trimmed python version (#279)