diff --git a/taskiq/cli/scheduler/run.py b/taskiq/cli/scheduler/run.py index 03c9faf6..c7ee03f1 100644 --- a/taskiq/cli/scheduler/run.py +++ b/taskiq/cli/scheduler/run.py @@ -99,7 +99,10 @@ def is_cron_task_now( # If timezone was specified as string we convert it timezone # offset and then apply. elif offset and isinstance(offset, str): - now = now.astimezone(ZoneInfo(offset)) + try: + now = now.astimezone(ZoneInfo(offset)) + except Exception as e: + raise CronValueError(e) from e try: return pycron.is_now(cron_value, now) diff --git a/tests/cli/scheduler/test_is_cron_task_now.py b/tests/cli/scheduler/test_is_cron_task_now.py index bbbe079b..630da454 100644 --- a/tests/cli/scheduler/test_is_cron_task_now.py +++ b/tests/cli/scheduler/test_is_cron_task_now.py @@ -75,3 +75,21 @@ def test_is_cron_task_now( def test_is_cron_task_now_invalid_cron() -> None: with pytest.raises(CronValueError): is_cron_task_now("invalid cron", datetime.now()) + + +def test_is_cron_task_now_invalid_offset_string() -> None: + with pytest.raises(CronValueError): + is_cron_task_now( + cron_value="* * * * *", + now=datetime.now(timezone.utc), + offset="UTC+3", + ) + + +def test_is_cron_task_now_unknown_timezone_name() -> None: + with pytest.raises(CronValueError): + is_cron_task_now( + cron_value="* * * * *", + now=datetime.now(timezone.utc), + offset="Europa/Madrid", + )