diff --git a/platypush/backend/alarm.py b/platypush/backend/alarm.py index 8e50a140..385b3dbe 100644 --- a/platypush/backend/alarm.py +++ b/platypush/backend/alarm.py @@ -1,4 +1,5 @@ import datetime +import enum import os import time import threading @@ -6,7 +7,7 @@ import threading from typing import Optional, Union, Dict, Any, List import croniter -import enum +from dateutil.tz import gettz from platypush.backend import Backend from platypush.context import get_bus, get_plugin @@ -54,18 +55,19 @@ class Alarm: self._runtime_snooze_interval = snooze_interval def get_next(self) -> float: - now = time.time() + now = datetime.datetime.now().replace(tzinfo=gettz()) try: cron = croniter.croniter(self.when, now) return cron.get_next() except (AttributeError, croniter.CroniterBadCronError): try: - timestamp = datetime.datetime.fromisoformat(self.when).timestamp() + timestamp = datetime.datetime.fromisoformat(self.when).replace(tzinfo=gettz()) except (TypeError, ValueError): - timestamp = (datetime.datetime.now() + datetime.timedelta(seconds=int(self.when))).timestamp() + timestamp = (datetime.datetime.now().replace(tzinfo=gettz()) + + datetime.timedelta(seconds=int(self.when))) - return timestamp if timestamp >= now else None + return timestamp.timestamp() if timestamp >= now else None def is_enabled(self): return self._enabled diff --git a/setup.py b/setup.py index 1aecaa46..35305e9b 100755 --- a/setup.py +++ b/setup.py @@ -163,6 +163,7 @@ setup( 'wheel', 'zeroconf>=0.27.0', 'tz', + 'python-dateutil', ], extras_require={ @@ -173,9 +174,9 @@ setup( # Support for Pushbullet backend and plugin 'pushbullet': ['pushbullet.py @ https://github.com/rbrcsk/pushbullet.py/tarball/master'], # Support for HTTP backend - 'http': ['flask', 'python-dateutil', 'frozendict', 'bcrypt'], + 'http': ['flask', 'frozendict', 'bcrypt'], # Support for uWSGI HTTP backend - 'uwsgi': ['flask', 'python-dateutil', 'frozendict', 'uwsgi', 'bcrypt'], + 'uwsgi': ['flask', 'frozendict', 'uwsgi', 'bcrypt'], # Support for MQTT backends 'mqtt': ['paho-mqtt'], # Support for RSS feeds parser @@ -220,7 +221,7 @@ setup( # Support for serial port plugin 'serial': ['pyserial'], # Support for ICal calendars - 'ical': ['icalendar', 'python-dateutil'], + 'ical': ['icalendar'], # Support for joystick backend 'joystick': ['inputs'], # Support for Kodi plugin