GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — DISCUSSION: Should deserialized timestamps have a timezone? · Issue #279 · googleapis/google-cloud-python

DISCUSSION: Should deserialized timestamps have a timezone? #279

New issue
Copy link
New issue
Copy link
Closed
Closed
DISCUSSION: Should deserialized timestamps have a timezone?#279
Copy link
Assignees
dhermes
Labels
api: datastoreIssues related to the Datastore API.type: questionRequest for information or clarification. Not an issue.

Description

@dhermes
dhermes
opened on Oct 21, 2014
Issue body actions

Also relates to #278.

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.

For example

>>> from gcloud.datastore.datastore_v1_pb2 import Value
>>> value_pb = Value()
>>> import datetime
>>> import pytz
>>> timestamp = datetime.datetime.utcnow().replace(tzinfo=pytz.timezone('CET'))
>>> timestamp
datetime.datetime(2014, 10, 21, 23, 49, 31, 816554, tzinfo=<DstTzInfo 'CET' CET+1:00:00 STD>)
>>> from gcloud.datastore._helpers import _set_protobuf_value
>>> _set_protobuf_value(value_pb, timestamp)
>>> from gcloud.datastore._helpers import _get_value_from_value_pb
>>> _get_value_from_value_pb(value_pb)
datetime.datetime(2014, 10, 21, 22, 49, 31, 816554, tzinfo=<UTC>)

I realized this while doing a before/after dictionary comparison in the regression test

Activity

Next
  1. dhermes
    added 9 commits that reference this issue on Oct 21, 2014

    Remove notes about datetime.date objects and timezone matching.

    b1b2aec

    Remove notes about datetime.date objects and timezone matching.

    56262a5

    Remove notes about datetime.date objects and timezone matching.

    8fb33d4

    Remove notes about datetime.date objects and timezone matching.

    012b020

    Remove notes about datetime.date objects and timezone matching.

    cfdd423

    Remove notes about datetime.date objects and timezone matching.

    f4bdf54

    Remove notes about datetime.date objects and timezone matching.

    999c7a6

    Remove notes about datetime.date objects and timezone matching.

    c64389b

    Remove notes about datetime.date objects and timezone matching.

    6b4b7d1
  2. pcostell commented on Oct 27, 2014

    @pcostell
    pcostell
    on Oct 27, 2014
    Contributor
    More actions

    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.

  3. dhermes commented on Oct 27, 2014

    @dhermes
    dhermes
    on Oct 27, 2014
    ContributorAuthor
    More actions

    I am in favor of that approach.

    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.

  4. dhermes
    added a commit that references this issue on Oct 27, 2014

    Remove notes about datetime.date objects and timezone matching.

    f235466
  5. tseaver commented on Oct 27, 2014

    @tseaver
    tseaver
    on Oct 27, 2014
    Contributor
    More actions

    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).

  6. dhermes
    added a commit that references this issue on Oct 27, 2014

    Remove notes about datetime.date objects and timezone matching.

    b5cb512
  7. dhermes commented on Oct 27, 2014

    @dhermes
    dhermes
    on Oct 27, 2014
    ContributorAuthor
    More actions

    @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.

  8. 44 remaining items

  9. parthea
    added a commit that references this issue on Jan 10, 2025

    chore: Update gapic-generator-python to v1.16.1 (#279)

    31b19da
  10. parthea
    added 8 commits that reference this issue on Nov 24, 2025

    chore(python): bump idna from 3.4 to 3.7 in .kokoro (#279)

    c9178bd

    fix function signature for streaming rpc (#279)

    d5df42c

    chore: Update many dependencies (#279)

    acb2617

    chore(python): update dependencies in /.kokoro (#279)

    f845b86

    chore(main): release 2.5.1 (#279)

    22339f3

    chore(python): Use latest python runtime in prerelease_deps session (#…

    8fa7b63

    fix: Escape html special characters in `hocr_document_template.xml.j2` (

    02af25b

    fix: fix missing __ne__ methods (#279)

    b660853
  11. parthea
    added 5 commits that reference this issue on Mar 2, 2026

    build: update windows build script to use trimmed python version (#279)

    13aa9f0

    feat: add support for Python 3.10 (#279)

    94384e7

    dbapi: make Connection.close invoke rollback, guards for already closed

    0b90502

    chore(deps): update dependency importlib-resources to v5.10.0 (#279)

    ed4e0a2

    chore: release 1.31.2 (#279)

    ad64b18
  12. ohmayr
    added a commit that references this issue on Mar 31, 2026

    build: update windows build script to use trimmed python version (#279)

    babbedb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dhermes
    dhermes

Labels

api: datastoreIssues related to the Datastore API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.