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 Jan 15, 2024
1 parent 8804f3c commit a1a970b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 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_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 a1a970b

Please sign in to comment.