Skip to content

Commit

Permalink
Stop using pytz
Browse files Browse the repository at this point in the history
It's been removed in this PR:
celery#1680

Moreover, the test.txt syntax is invalid with our version of setuptools
  • Loading branch information
jbkkd committed Oct 5, 2023
1 parent ea48a80 commit fc46f7f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
13 changes: 7 additions & 6 deletions kombu/asynchronous/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@

from kombu.log import get_logger

try:
from pytz import utc
except ImportError: # pragma: no cover
utc = None

if sys.version_info >= (3, 9):
from zoneinfo import ZoneInfo
else:
from backports.zoneinfo import ZoneInfo

__all__ = ('Entry', 'Timer', 'to_timestamp')

logger = get_logger(__name__)

DEFAULT_MAX_INTERVAL = 2
EPOCH = datetime.utcfromtimestamp(0).replace(tzinfo=utc)
EPOCH = datetime.utcfromtimestamp(0).replace(tzinfo=ZoneInfo("UTC"))
IS_PYPY = hasattr(sys, 'pypy_version_info')

scheduled = namedtuple('scheduled', ('eta', 'priority', 'entry'))


def to_timestamp(d, default_timezone=utc, time=monotonic):
def to_timestamp(d, default_timezone=ZoneInfo("UTC"), time=monotonic):
"""Convert datetime to timestamp.
If d' is already a timestamp, then that will be used.
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytz>dev
pytest~=7.0.1
pytest-sugar
Pyro4
backports.zoneinfo>=0.2.1; python_version < '3.9'
8 changes: 6 additions & 2 deletions t/unit/utils/test_json.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from collections import namedtuple
from datetime import datetime
from decimal import Decimal
import sys
from unittest.mock import MagicMock, Mock
from uuid import uuid4

import pytest
import pytz

from kombu.utils.encoding import str_to_bytes
from kombu.utils.json import _DecodeError, dumps, loads

if sys.version_info >= (3, 9):
from zoneinfo import ZoneInfo
else:
from backports.zoneinfo import ZoneInfo

class Custom:

Expand All @@ -24,7 +28,7 @@ class test_JSONEncoder:

def test_datetime(self):
now = datetime.utcnow()
now_utc = now.replace(tzinfo=pytz.utc)
now_utc = now.replace(tzinfo=ZoneInfo("UTC"))
stripped = datetime(*now.timetuple()[:3])
serialized = loads(dumps({
'datetime': now,
Expand Down

0 comments on commit fc46f7f

Please sign in to comment.