Title: gcloud.datastore.helpers.get_value_from_protobuf() returns naive datetimes · Issue #131 · googleapis/google-cloud-python · GitHub
Open Graph Title: gcloud.datastore.helpers.get_value_from_protobuf() returns naive datetimes · Issue #131 · googleapis/google-cloud-python
X Title: gcloud.datastore.helpers.get_value_from_protobuf() returns naive datetimes · Issue #131 · googleapis/google-cloud-python
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 >>...
Open Graph 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 im...
X Description: Naive datetimes (without timezones) are explicitly coerced to UTC by 'get_protobuf_attribute_and_value': >>> import calendar >>> import datetime >>> import pytz &...
Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/131
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"gcloud.datastore.helpers.get_value_from_protobuf() returns naive datetimes","articleBody":"Naive datetimes (without timezones) are explicitly coerced to UTC by\n'get_protobuf_attribute_and_value':\n\n```\n\u003e\u003e\u003e import calendar\n\u003e\u003e\u003e import datetime\n\u003e\u003e\u003e import pytz\n\u003e\u003e\u003e from gcloud.datastore.helpers import get_protobuf_attribute_and_value\n\u003e\u003e\u003e naive = datetime.datetime(2014, 9, 16, 10, 19, 32, 4375) # no zone\n\u003e\u003e\u003e utc = datetime.datetime(2014, 9, 16, 10, 19, 32, 4375, pytz.utc)\n\u003e\u003e\u003e _, naive_micros = get_protobuf_attribute_and_value(naive)\n\u003e\u003e\u003e _, utc_micros = get_protobuf_attribute_and_value(utc)\n\u003e\u003e\u003e naive_micros == utc_micros\nTrue\n```\n\nBut the datetimes returned by 'get_value_from_protobuf' do not set the UTC\ntimezone:\n\n```\n\u003e\u003e\u003e from gcloud.datastore.helpers import get_value_from_protobuf\n\u003e\u003e\u003e from gcloud.datastore.datastore_v1_pb2 import Property\n\u003e\u003e\u003e pb = Property()\n\u003e\u003e\u003e pb.value.timestamp_microseconds_value = utc_micros\n\u003e\u003e\u003e get_value_from_protobuf(pb) == utc\nTypeError: can't compare offset-naive and offset-aware datetimes\n\u003e\u003e\u003e get_value_from_protobuf(pb) == naive\nTrue\n```\n\nLeaving 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?\n","author":{"url":"https://github.com/tseaver","@type":"Person","name":"tseaver"},"datePublished":"2014-09-16T15:08:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/131/google-cloud-python/issues/131"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bb902ea1-c53b-2782-a2fb-a354598b07af |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A3AE:37F343:117804C:1762272:6A4D8D5E |
| html-safe-nonce | c8ca569b12b47c199fd78259d72972cf956548bd197c16900694f831c8196a53 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0FFOjM3RjM0MzoxMTc4MDRDOjE3NjIyNzI6NkE0RDhENUUiLCJ2aXNpdG9yX2lkIjoiNjk1MDI3NDU4MTY0Mzc1ODk0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b8f9b07e31e02736e1a2f3195a35a40e253d5986c0e310f4447211f3f7361404 |
| hovercard-subject-tag | issue:42893005 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/google-cloud-python/131/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2418bed1f6a5ff07927740e4ba1ae3c536c5d24a4f239e9ed75f5a7a4ba9134e/googleapis/google-cloud-python/issues/131 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2418bed1f6a5ff07927740e4ba1ae3c536c5d24a4f239e9ed75f5a7a4ba9134e/googleapis/google-cloud-python/issues/131 |
| og:image:alt | 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 im... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tseaver |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9f8758a3953dfe943439713a6fa4f90d542a3431f10e861ca03dd7f39009f320 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/google-cloud-python git https://github.com/googleapis/google-cloud-python.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 16316451 |
| octolytics-dimension-repository_nwo | googleapis/google-cloud-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 16316451 |
| octolytics-dimension-repository_network_root_nwo | googleapis/google-cloud-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bffd5484f01713a661b03469b77678f72b6574ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width