Fixed croniter timezone offset logic mismatch

This commit is contained in:
Fabio Manganiello 2020-11-21 01:36:37 +01:00
parent 0c0e7411f7
commit 9dacd2d3c9
2 changed files with 11 additions and 8 deletions

View file

@ -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

View file

@ -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