Skip to content

Commit

Permalink
Do not use deprecated datetime.utcnow and datetime.utcfromtimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
decaz committed Dec 28, 2023
1 parent 2e63f3a commit 8225acf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion aio_pika/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
ConsumerTag = str

MILLISECONDS = 1000
ZERO_TIME = datetime.utcfromtimestamp(0)
ZERO_TIME = datetime(1970, 1, 1)


class SSLOptions(TypedDict, total=False):
Expand Down
8 changes: 4 additions & 4 deletions aio_pika/message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time
import warnings
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from functools import singledispatch
from pprint import pformat
from types import TracebackType
Expand Down Expand Up @@ -86,12 +86,12 @@ def encode_timestamp_datetime(value: datetime) -> datetime:
@encode_timestamp.register(float)
@encode_timestamp.register(int)
def encode_timestamp_number(value: Union[int, float]) -> datetime:
return datetime.utcfromtimestamp(value)
return datetime.fromtimestamp(value, tz=timezone.utc)


@encode_timestamp.register(timedelta)
def encode_timestamp_timedelta(value: timedelta) -> datetime:
return datetime.utcnow() + value
return datetime.now(tz=timezone.utc) + value


@encode_timestamp.register(NoneType) # type: ignore
Expand All @@ -112,7 +112,7 @@ def decode_timestamp_datetime(value: datetime) -> datetime:
@decode_timestamp.register(float)
@decode_timestamp.register(int)
def decode_timestamp_number(value: Union[float, int]) -> datetime:
return datetime.utcfromtimestamp(value)
return datetime.fromtimestamp(value, tz=timezone.utc)


@decode_timestamp.register(time.struct_time)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_amqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import time
import uuid
from datetime import datetime
from datetime import datetime, timezone
from typing import Callable, Optional
from unittest import mock

Expand Down Expand Up @@ -369,7 +369,7 @@ async def test_incoming_message_info(
message_id=shortuuid.uuid(),
priority=0,
reply_to="test",
timestamp=datetime.utcfromtimestamp(int(time.time())),
timestamp=datetime.fromtimestamp(int(time.time()), tz=timezone.utc),
type="0",
user_id="guest",
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time
from copy import copy
from datetime import datetime
from datetime import datetime, timezone
from typing import List, Tuple

import shortuuid
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_message_info():
redelivered=None,
reply_to="test",
routing_key=None,
timestamp=datetime.utcfromtimestamp(int(time.time())),
timestamp=datetime.fromtimestamp(int(time.time()), tz=timezone.utc),
type="0",
user_id="guest",
)
Expand Down

0 comments on commit 8225acf

Please sign in to comment.