Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 7817807

Browse files
committed
fix: remove pytz
1 parent 7769f46 commit 7817807

4 files changed

Lines changed: 15 additions & 20 deletions

File tree

google/cloud/ndb/model.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ class Person(Model):
259259
import six
260260
import zlib
261261

262-
import pytz
263-
264262
from google.cloud.datastore import entity as ds_entity_module
265263
from google.cloud.datastore import helpers
266264
from google.cloud.datastore_v1.proto import entity_pb2
@@ -3880,11 +3878,11 @@ def _from_base_type(self, value):
38803878
if isinstance(value, six.integer_types):
38813879
# Projection query, value is integer nanoseconds
38823880
seconds = value / 1e6
3883-
value = datetime.datetime.fromtimestamp(seconds, pytz.utc)
3881+
value = datetime.datetime.fromtimestamp(seconds, datetime.timezone.utc)
38843882

38853883
if self._tzinfo is not None:
38863884
if value.tzinfo is None:
3887-
value = value.replace(tzinfo=pytz.utc)
3885+
value = value.replace(tzinfo=datetime.timezone.utc)
38883886
return value.astimezone(self._tzinfo)
38893887

38903888
elif value.tzinfo is not None:
@@ -3903,7 +3901,7 @@ def _to_base_type(self, value):
39033901
TypeError: If ``value`` is not a :class:`~key.Key`.
39043902
"""
39053903
if self._tzinfo is not None and value.tzinfo is not None:
3906-
return value.astimezone(pytz.utc)
3904+
return value.astimezone(datetime.timezone.utc)
39073905

39083906

39093907
class DateProperty(DateTimeProperty):

tests/system/test_crud.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import datetime
1919
import os
2020
import pickle
21-
import pytz
2221
import random
2322
import threading
2423
import zlib
@@ -1336,10 +1335,10 @@ def test_insert_autonow_property_with_tz(dispose_of):
13361335
"""
13371336

13381337
class SomeKind(ndb.Model):
1339-
created_at = ndb.DateTimeProperty(auto_now_add=True, tzinfo=pytz.utc)
1340-
updated_at = ndb.DateTimeProperty(auto_now=True, tzinfo=pytz.utc)
1338+
created_at = ndb.DateTimeProperty(auto_now_add=True, tzinfo=datetime.timezone.utc)
1339+
updated_at = ndb.DateTimeProperty(auto_now=True, tzinfo=datetime.timezone.utc)
13411340

1342-
now = datetime.datetime.now(pytz.utc)
1341+
now = datetime.datetime.now(datetime.timezone.utc)
13431342
entity = SomeKind()
13441343
key = entity.put()
13451344
dispose_of(key._key)
@@ -1361,10 +1360,10 @@ def test_insert_datetime_property_with_tz(dispose_of):
13611360
"""
13621361

13631362
class SomeKind(ndb.Model):
1364-
alarm1 = ndb.DateTimeProperty(tzinfo=pytz.utc)
1365-
alarm2 = ndb.DateTimeProperty(tzinfo=pytz.utc)
1363+
alarm1 = ndb.DateTimeProperty(tzinfo=datetime.timezone.utc)
1364+
alarm2 = ndb.DateTimeProperty(tzinfo=datetime.timezone.utc)
13661365

1367-
now = datetime.datetime.now(pytz.utc)
1366+
now = datetime.datetime.now(datetime.timezone.utc)
13681367
entity = SomeKind(
13691368
alarm1=now,
13701369
alarm2=datetime.datetime.utcnow(), # naive

tests/system/test_query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import uuid
2323

2424
import pytest
25-
import pytz
2625

2726
import test_utils.system
2827

@@ -247,13 +246,13 @@ def test_projection_datetime(ds_entity):
247246
ds_entity(
248247
KIND,
249248
entity_id,
250-
foo=datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC),
249+
foo=datetime.datetime(2010, 5, 12, 2, 42, tzinfo=datetime.timezone.utc),
251250
)
252251
entity_id = test_utils.system.unique_resource_id()
253252
ds_entity(
254253
KIND,
255254
entity_id,
256-
foo=datetime.datetime(2010, 5, 12, 2, 43, tzinfo=pytz.UTC),
255+
foo=datetime.datetime(2010, 5, 12, 2, 43, tzinfo=datetime.timezone.utc),
257256
)
258257

259258
class SomeKind(ndb.Model):

tests/unit/test_model.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import datetime
1616
import pickle
17-
import pytz
1817
import six
1918
import types
2019
import zlib
@@ -2748,7 +2747,7 @@ def test__validate_invalid():
27482747
@staticmethod
27492748
def test__validate_with_tz():
27502749
prop = model.DateTimeProperty(name="dt_val")
2751-
value = datetime.datetime.now(tz=pytz.utc)
2750+
value = datetime.datetime.now(tz=datetime.timezone.utc)
27522751
with pytest.raises(exceptions.BadValueError):
27532752
prop._validate(value)
27542753

@@ -2819,13 +2818,13 @@ def test__from_base_type_no_timezone():
28192818
@staticmethod
28202819
def test__from_base_type_timezone():
28212820
prop = model.DateTimeProperty(name="dt_val")
2822-
value = datetime.datetime(2010, 5, 12, tzinfo=pytz.utc)
2821+
value = datetime.datetime(2010, 5, 12, tzinfo=datetime.timezone.utc)
28232822
assert prop._from_base_type(value) == datetime.datetime(2010, 5, 12)
28242823

28252824
@staticmethod
28262825
def test__from_base_type_convert_timezone():
28272826
prop = model.DateTimeProperty(name="dt_val", tzinfo=timezone(-4))
2828-
value = datetime.datetime(2010, 5, 12, tzinfo=pytz.utc)
2827+
value = datetime.datetime(2010, 5, 12, tzinfo=datetime.timezone.utc)
28292828
assert prop._from_base_type(value) == datetime.datetime(
28302829
2010, 5, 11, 20, tzinfo=timezone(-4)
28312830
)
@@ -2855,7 +2854,7 @@ def test__to_base_type_convert_to_utc():
28552854
prop = model.DateTimeProperty(name="dt_val", tzinfo=timezone(-4))
28562855
value = datetime.datetime(2010, 5, 12, tzinfo=timezone(-4))
28572856
assert prop._to_base_type(value) == datetime.datetime(
2858-
2010, 5, 12, 4, tzinfo=pytz.utc
2857+
2010, 5, 12, 4, tzinfo=datetime.timezone.utc
28592858
)
28602859

28612860

0 commit comments

Comments
 (0)