Skip to content

Commit

Permalink
Fix deprecation warnings for utc shorthands
Browse files Browse the repository at this point in the history
  • Loading branch information
leonhard-s committed Nov 4, 2024
1 parent 9b30d1d commit 4627efe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions auraxium/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def __init__(self, type_: Type[_Ps2ObjectT], query: Query,
self._data: List[_Ps2ObjectT]
self._index: int
self._lock = asyncio.Lock()
self._last_fetched = datetime.datetime.utcfromtimestamp(0)
max_age = datetime.datetime.utcnow() - self._last_fetched
self._last_fetched = datetime.datetime.fromtimestamp(0, datetime.UTC)
max_age = datetime.datetime.now(datetime.UTC) - self._last_fetched
assert self._ttu < max_age.total_seconds()

async def _poll(self) -> None:
Expand All @@ -70,7 +70,7 @@ async def _poll(self) -> None:
payload = await self._client.request(self.query)
list_ = self._resolve_nested_payload(payload)
self._data = [self._type(d, client=self._client) for d in list_]
self._last_fetched = datetime.datetime.utcnow()
self._last_fetched = datetime.datetime.now(datetime.UTC)

def _resolve_nested_payload(self, payload: CensusData) -> List[CensusData]:
"""Resolve the object payload.
Expand Down Expand Up @@ -143,7 +143,7 @@ def __aiter__(self) -> 'SequenceProxy[_Ps2ObjectT]':
return self

async def __anext__(self) -> _Ps2ObjectT:
age = datetime.datetime.utcnow() - self._last_fetched
age = datetime.datetime.now(datetime.UTC) - self._last_fetched
if age.total_seconds() > self._ttu:
if self._index > -1:
warnings.warn('Data went stale during iteration, polling new')
Expand Down Expand Up @@ -181,7 +181,7 @@ async def resolve(self) -> Optional[_Ps2ObjectT]:
:return: The object, or :obj:`None` if no match was found.
"""
age = datetime.datetime.utcnow() - self._last_fetched
age = datetime.datetime.now(datetime.UTC) - self._last_fetched
if age.total_seconds() > self._ttu:
await self._poll()
try:
Expand Down
2 changes: 1 addition & 1 deletion auraxium/event/_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async def run(self, event: Event) -> None:
:param Event event: The event to pass to the trigger action.
"""
self.last_run = datetime.datetime.utcnow()
self.last_run = datetime.datetime.now(datetime.UTC)
if self.action is None: # pragma: no cover
warnings.warn(f'Trigger {self.name} run with no action specified')
return
Expand Down
4 changes: 2 additions & 2 deletions auraxium/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ def _utc_from_timestamp(cls, value: str,
) -> datetime.datetime:
"""Convert timestamps to UTC datetimes."""
_ = info
return datetime.datetime.utcfromtimestamp(int(value))
return datetime.datetime.fromtimestamp(int(value), datetime.UTC)

@property
def age(self) -> float:
"""The age of the event in seconds."""
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.UTC)
return (now - self.timestamp).total_seconds()


Expand Down

0 comments on commit 4627efe

Please sign in to comment.