Skip to content

Commit

Permalink
Add compatibility hack for Python 3.12's broken utc stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Nov 21, 2023
1 parent a624af3 commit bdbe58c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion huey/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from huey.utils import string_type
from huey.utils import time_clock
from huey.utils import to_timestamp
from huey.utils import utcnow


logger = logging.getLogger('huey')
Expand Down Expand Up @@ -343,7 +344,7 @@ def delete(self, key):
return self.storage.delete_data(key)

def _get_timestamp(self):
return (datetime.datetime.utcnow() if self.utc else
return (utcnow() if self.utc else
datetime.datetime.now())

def execute(self, task, timestamp=None):
Expand Down
10 changes: 9 additions & 1 deletion huey/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
except ImportError:
fcntl = None

if sys.version_info < (3, 12):
utcnow = datetime.datetime.utcnow
else:
def utcnow():
return (datetime.datetime
.now(datetime.timezone.utc)
.replace(tzinfo=None))


Error = namedtuple('Error', ('metadata',))

Expand Down Expand Up @@ -86,7 +94,7 @@ def normalize_time(eta=None, delay=None, utc=True):
if not ((delay is None) ^ (eta is None)):
raise ValueError('Specify either an eta (datetime) or delay (seconds)')
elif delay:
method = (utc and datetime.datetime.utcnow or
method = (utc and utcnow() or
datetime.datetime.now)
if not isinstance(delay, datetime.timedelta):
delay = datetime.timedelta(seconds=delay)
Expand Down

0 comments on commit bdbe58c

Please sign in to comment.