Skip to content

Commit bd605a5

Browse files
committed
fix: localtime->gmtime
1 parent 31185df commit bd605a5

File tree

2 files changed

+33
-51
lines changed

2 files changed

+33
-51
lines changed

google/cloud/spanner_dbapi/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def Timestamp(year, month, day, hour, minute, second):
2525

2626

2727
def DateFromTicks(ticks):
28-
return Date(*time.localtime(ticks)[:3])
28+
return Date(*time.gmtime(ticks)[:3])
2929

3030

3131
def TimeFromTicks(ticks):
32-
return Time(*time.localtime(ticks)[3:6])
32+
return Time(*time.gmtime(ticks)[3:6])
3333

3434

3535
def TimestampFromTicks(ticks):
36-
return Timestamp(*time.localtime(ticks)[:6])
36+
return Timestamp(*time.gmtime(ticks)[:6])
3737

3838

3939
def Binary(string):

tests/spanner_dbapi/test_types.py

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,68 +18,50 @@
1818
)
1919
from google.cloud.spanner_dbapi.utils import PeekIterator
2020

21-
tzUTC = 0 # 0 hours offset from UTC)
22-
utcOffset = time.timezone # offset for current timezone
23-
2421
class TypesTests(TestCase):
2522
def test_Date(self):
26-
got = Date(2019, 11, 3)
27-
want = datetime.date(2019, 11, 3)
28-
self.assertEqual(got, want, "mismatch between conversion")
23+
actual = Date(2019, 11, 3)
24+
expected = datetime.date(2019, 11, 3)
25+
self.assertEqual(actual, expected, "mismatch between conversion")
2926

3027
def test_Time(self):
31-
got = Time(23, 8, 19)
32-
want = datetime.time(23, 8, 19)
33-
self.assertEqual(got, want, "mismatch between conversion")
28+
actual = Time(23, 8, 19)
29+
expected = datetime.time(23, 8, 19)
30+
self.assertEqual(actual, expected, "mismatch between conversion")
3431

3532
def test_Timestamp(self):
36-
got = Timestamp(2019, 11, 3, 23, 8, 19)
37-
want = datetime.datetime(2019, 11, 3, 23, 8, 19)
38-
self.assertEqual(got, want, "mismatch between conversion")
33+
actual = Timestamp(2019, 11, 3, 23, 8, 19)
34+
expected = datetime.datetime(2019, 11, 3, 23, 8, 19)
35+
self.assertEqual(actual, expected, "mismatch between conversion")
3936

4037
def test_DateFromTicks(self):
41-
epochTicks = 1572822862.9782631 # Sun Nov 03 23:14:22 2019
42-
got = DateFromTicks(epochTicks + utcOffset)
43-
# Since continuous integration infrastructure such as Travis CI
44-
# uses clocks on UTC, it is useful to be able to compare against
45-
# either of UTC or the known standard time.
46-
want = (
47-
datetime.date(2019, 11, 3),
48-
datetime.datetime(2019, 11, 4, tzUTC).date(),
49-
)
50-
matches = got in want
38+
epochTicks = 1572822862 # Sun Nov 03 23:14:22 2019 GMT
39+
40+
actual = DateFromTicks(epochTicks)
41+
expected = datetime.date(2019, 11, 3)
42+
5143
self.assertTrue(
52-
matches, "`%s` not present in any of\n`%s`" % (got, want)
44+
actual == expected, "`%s` doesn't match\n`%s`" % (actual, expected)
5345
)
5446

5547
def test_TimeFromTicks(self):
56-
epochTicks = 1572822862.9782631 # Sun Nov 03 23:14:22 2019
57-
got = TimeFromTicks(epochTicks + utcOffset)
58-
# Since continuous integration infrastructure such as Travis CI
59-
# uses clocks on UTC, it is useful to be able to compare against
60-
# either of UTC or the known standard time.
61-
want = (
62-
datetime.time(23, 14, 22),
63-
datetime.datetime(2019, 11, 4, 7, 14, 22, tzUTC).time(),
64-
)
65-
matches = got in want
48+
epochTicks = 1572822862 # Sun Nov 03 23:14:22 2019 GMT
49+
50+
actual = TimeFromTicks(epochTicks)
51+
expected = datetime.time(23, 14, 22)
52+
6653
self.assertTrue(
67-
matches, "`%s` not present in any of\n`%s`" % (got, want)
54+
actual == expected, "`%s` doesn't match\n`%s`" % (actual, expected)
6855
)
6956

7057
def test_TimestampFromTicks(self):
71-
epochTicks = 1572822862.9782631 # Sun Nov 03 23:14:22 2019
72-
got = TimestampFromTicks(epochTicks + utcOffset)
73-
# Since continuous integration infrastructure such as Travis CI
74-
# uses clocks on UTC, it is useful to be able to compare against
75-
# either of UTC or the known standard time.
76-
want = (
77-
datetime.datetime(2019, 11, 3, 23, 14, 22),
78-
datetime.datetime(2019, 11, 4, 7, 14, 22, tzUTC),
79-
)
80-
matches = got in want
58+
epochTicks = 1572822862 # Sun Nov 03 23:14:22 2019 GMT
59+
60+
actual = TimestampFromTicks(epochTicks)
61+
expected = datetime.datetime(2019, 11, 3, 23, 14, 22)
62+
8163
self.assertTrue(
82-
matches, "`%s` not present in any of\n`%s`" % (got, want)
64+
actual == expected, "`%s` doesn't match\n`%s`" % (actual, expected)
8365
)
8466

8567
def test_PeekIterator(self):
@@ -91,8 +73,8 @@ def test_PeekIterator(self):
9173
("no_args", (), []),
9274
]
9375

94-
for name, data_in, want in cases:
76+
for name, data_in, expected in cases:
9577
with self.subTest(name=name):
9678
pitr = PeekIterator(data_in)
97-
got = list(pitr)
98-
self.assertEqual(got, want)
79+
actual = list(pitr)
80+
self.assertEqual(actual, expected)

0 commit comments

Comments
 (0)