Skip to content
Permalink
Browse files
Add support for timezone as string in cron interval timetable (#23279)
  • Loading branch information
malthe committed May 4, 2022
1 parent dfe0f75 commit fdf1a537605be579d28759415a3a5905c466a7a3
Showing 2 changed files with 9 additions and 1 deletion.
@@ -127,8 +127,11 @@ class CronDataIntervalTimetable(_DataIntervalTimetable):
Don't pass ``@once`` in here; use ``OnceTimetable`` instead.
"""

def __init__(self, cron: str, timezone: Timezone) -> None:
def __init__(self, cron: str, timezone: Union[str, Timezone]) -> None:
self._expression = cron_presets.get(cron, cron)

if isinstance(timezone, str):
timezone = Timezone(timezone)
self._timezone = timezone

descriptor = ExpressionDescriptor(
@@ -153,3 +153,8 @@ def test_validate_failure(timetable: Timetable, error_message: str) -> None:
with pytest.raises(AirflowTimetableInvalid) as ctx:
timetable.validate()
assert str(ctx.value) == error_message


def test_cron_interval_timezone_from_string():
timetable = CronDataIntervalTimetable("@hourly", "UTC")
assert timetable.serialize()['timezone'] == 'UTC'

0 comments on commit fdf1a53

Please sign in to comment.