Don't fail when tz is incorrect (#8723)

* Don't fail when tz is incorrect

* Fix import
This commit is contained in:
Nicolas Mowen 2023-11-23 05:43:02 -06:00 committed by GitHub
parent 1dc42d2904
commit 18062eca06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,7 @@ import pytz
import yaml import yaml
from ruamel.yaml import YAML from ruamel.yaml import YAML
from tzlocal import get_localzone from tzlocal import get_localzone
from zoneinfo import ZoneInfoNotFoundError
from frigate.const import REGEX_HTTP_CAMERA_USER_PASS, REGEX_RTSP_CAMERA_USER_PASS from frigate.const import REGEX_HTTP_CAMERA_USER_PASS, REGEX_RTSP_CAMERA_USER_PASS
@ -266,7 +267,16 @@ def find_by_key(dictionary, target_key):
def get_tomorrow_at_time(hour: int) -> datetime.datetime: def get_tomorrow_at_time(hour: int) -> datetime.datetime:
"""Returns the datetime of the following day at 2am.""" """Returns the datetime of the following day at 2am."""
try:
tomorrow = datetime.datetime.now(get_localzone()) + datetime.timedelta(days=1) tomorrow = datetime.datetime.now(get_localzone()) + datetime.timedelta(days=1)
except ZoneInfoNotFoundError:
tomorrow = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(
days=1
)
logger.warning(
"Using utc for maintenance due to missing or incorrect timezone set"
)
return tomorrow.replace(hour=hour, minute=0, second=0).astimezone( return tomorrow.replace(hour=hour, minute=0, second=0).astimezone(
datetime.timezone.utc datetime.timezone.utc
) )