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 1a6df53 commit 5522438
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions tests/models/test_datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import time
from datetime import timedelta
from datetime import timezone
from datetime import UTC
from typing import Dict
from unittest import TestCase

Expand Down Expand Up @@ -223,13 +224,13 @@ 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(UTC).replace(fractional_second=0, second=0, minute=1),
)

now = datetime.utcnow().replace(microsecond=0, second=0, minute=1)
now = datetime.now(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(UTC).replace(fractional_second=0, second=0, minute=1),
)

def test_comparisons(self):
Expand Down Expand Up @@ -369,13 +370,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(UTC).replace(fractional_second=0, second=0, minute=1),
)

now = datetime.utcnow().replace(microsecond=0, second=0, minute=1)
now = datetime.now(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(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.datetime.now(datetime.UTC)"""
return cls.from_datetime(datetime.datetime.now(datetime.UTC))

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.datetime.now(datetime.UTC)"""
return cls.from_time(datetime.datetime.now(datetime.UTC).time())

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

0 comments on commit 5522438

Please sign in to comment.