Skip to content
Permalink
Browse files
fix: use datetime timezone info when generating timestamp strings (#236)
* fix: use datetime timezone when generating timestamp strings

* style: fix lint

Co-authored-by: larkee <larkee@users.noreply.github.com>
  • Loading branch information
larkee and larkee committed Feb 17, 2021
1 parent 0375914 commit 539f14533afd348a328716aa511d453ca3bb19f5
Showing with 13 additions and 1 deletion.
  1. +1 −1 google/cloud/spanner_v1/_helpers.py
  2. +12 −0 tests/unit/test__helpers.py
@@ -118,7 +118,7 @@ def _make_value_pb(value):
if isinstance(value, datetime_helpers.DatetimeWithNanoseconds):
return Value(string_value=value.rfc3339())
if isinstance(value, datetime.datetime):
return Value(string_value=_datetime_to_rfc3339(value))
return Value(string_value=_datetime_to_rfc3339(value, ignore_zone=False))
if isinstance(value, datetime.date):
return Value(string_value=value.isoformat())
if isinstance(value, six.binary_type):
@@ -215,6 +215,18 @@ def test_w_datetime(self):
self.assertIsInstance(value_pb, Value)
self.assertEqual(value_pb.string_value, datetime_helpers.to_rfc3339(now))

def test_w_timestamp_w_tz(self):
import datetime
import pytz
from google.protobuf.struct_pb2 import Value

when = datetime.datetime(
2021, 2, 8, 0, 0, 0, tzinfo=pytz.timezone("US/Mountain")
)
value_pb = self._callFUT(when)
self.assertIsInstance(value_pb, Value)
self.assertEqual(value_pb.string_value, "2021-02-08T07:00:00.000000Z")

def test_w_numeric(self):
import decimal
from google.protobuf.struct_pb2 import Value

0 comments on commit 539f145

Please sign in to comment.