From 18062eca06a223b4c22f69a6172ef086c4ffbf0e Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Thu, 23 Nov 2023 05:43:02 -0600 Subject: [PATCH] Don't fail when tz is incorrect (#8723) * Don't fail when tz is incorrect * Fix import --- frigate/util/builtin.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frigate/util/builtin.py b/frigate/util/builtin.py index ff30952bb..dcdf21c6a 100644 --- a/frigate/util/builtin.py +++ b/frigate/util/builtin.py @@ -16,6 +16,7 @@ import pytz import yaml from ruamel.yaml import YAML from tzlocal import get_localzone +from zoneinfo import ZoneInfoNotFoundError 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: """Returns the datetime of the following day at 2am.""" - tomorrow = datetime.datetime.now(get_localzone()) + datetime.timedelta(days=1) + try: + 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( datetime.timezone.utc )