Skip to content

Commit

Permalink
Replace depreated datetime.datetime.utcnow()
Browse files Browse the repository at this point in the history
  • Loading branch information
tefra committed Dec 18, 2023
1 parent 76baf3a commit f9b8739
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions tests/models/test_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,17 @@ def test_datetime_helpers(self):
now = datetime.now(tz=timezone.utc).replace(microsecond=0, second=0, minute=1)
self.assertEqual(
XmlDateTime.from_datetime(now),
XmlDateTime.utcnow().replace(fractional_second=0, second=0, minute=1),
XmlDateTime.now(timezone.utc).replace(
fractional_second=0, second=0, minute=1
),
)

now = datetime.utcnow().replace(microsecond=0, second=0, minute=1)
now = datetime.now(timezone.utc).replace(microsecond=0, second=0, minute=1)
self.assertEqual(
XmlDateTime.from_datetime(now),
XmlDateTime.utcnow().replace(fractional_second=0, second=0, minute=1),
XmlDateTime.now(timezone.utc).replace(
fractional_second=0, second=0, minute=1
),
)

def test_comparisons(self):
Expand Down Expand Up @@ -369,13 +373,13 @@ def test_datetime_helpers(self):
now = datetime.now(tz=timezone.utc).replace(microsecond=0, second=0, minute=1)
self.assertEqual(
XmlTime.from_time(now.time()),
XmlTime.utcnow().replace(fractional_second=0, second=0, minute=1),
XmlTime.now(timezone.utc).replace(fractional_second=0, second=0, minute=1),
)

now = datetime.utcnow().replace(microsecond=0, second=0, minute=1)
now = datetime.now(timezone.utc).replace(microsecond=0, second=0, minute=1)
self.assertEqual(
XmlTime.from_time(now.time()),
XmlTime.utcnow().replace(fractional_second=0, second=0, minute=1),
XmlTime.now(timezone.utc).replace(fractional_second=0, second=0, minute=1),
)

def test_comparisons(self):
Expand Down
8 changes: 4 additions & 4 deletions xsdata/models/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ def now(cls, tz: Optional[datetime.timezone] = None) -> "XmlDateTime":

@classmethod
def utcnow(cls) -> "XmlDateTime":
"""Initialize from datetime.datetime.utcnow()"""
return cls.from_datetime(datetime.datetime.utcnow())
"""Initialize from datetime.now(timezone.utc)"""
return cls.from_datetime(datetime.datetime.now(datetime.timezone.utc))

Check warning on line 232 in xsdata/models/datatype.py

View check run for this annotation

Codecov / codecov/patch

xsdata/models/datatype.py#L232

Added line #L232 was not covered by tests

def to_datetime(self) -> datetime.datetime:
"""Return a :class:`datetime.datetime` instance."""
Expand Down Expand Up @@ -411,8 +411,8 @@ def now(cls, tz: Optional[datetime.timezone] = None) -> "XmlTime":

@classmethod
def utcnow(cls) -> "XmlTime":
"""Initialize from datetime.datetime.utcnow()"""
return cls.from_time(datetime.datetime.utcnow().time())
"""Initialize from datetime.now(timezone.utc)"""
return cls.from_time(datetime.datetime.now(datetime.timezone.utc).time())

Check warning on line 415 in xsdata/models/datatype.py

View check run for this annotation

Codecov / codecov/patch

xsdata/models/datatype.py#L415

Added line #L415 was not covered by tests

def to_time(self) -> datetime.time:
"""Return a :class:`datetime.time` instance."""
Expand Down

0 comments on commit f9b8739

Please sign in to comment.