diff --git a/sqlmesh/core/node.py b/sqlmesh/core/node.py index 73e4a31940..d572b4036c 100644 --- a/sqlmesh/core/node.py +++ b/sqlmesh/core/node.py @@ -512,7 +512,7 @@ def cron_floor(self, value: TimeLike, estimate: bool = False) -> datetime: Returns: The timestamp floor. """ - return self.croniter(self.cron_next(value, estimate=estimate)).get_prev(estimate=True) + return self.croniter(self.cron_next(value, estimate=estimate)).get_prev(estimate=estimate) def text_diff(self, other: Node, rendered: bool = False) -> str: """Produce a text diff against another node. diff --git a/tests/core/test_snapshot.py b/tests/core/test_snapshot.py index d92f7dcc18..57f2b4965e 100644 --- a/tests/core/test_snapshot.py +++ b/tests/core/test_snapshot.py @@ -515,6 +515,26 @@ def test_missing_intervals_end_bounded_with_ignore_cron(make_snapshot): ] +@time_machine.travel("2023-01-02 20:30:00 UTC", tick=False) +def test_missing_intervals_cron_with_hour_range(make_snapshot): + snapshot = make_snapshot( + SqlModel( + name="test_model", + kind=IncrementalByTimeRangeKind(time_column=TimeColumn(column="ds")), + cron="0 9-17 * * *", + query=parse_one("SELECT 1, ds FROM name"), + ) + ) + + # The last run was due at 17:00 and the next one is due at 09:00 the following day + now = "2023-01-02 20:30:00" + assert snapshot.node.cron_floor(now) == to_datetime("2023-01-02 17:00:00") + assert snapshot.missing_intervals("2023-01-02 15:00:00", now) == [ + (to_timestamp("2023-01-02 15:00:00"), to_timestamp("2023-01-02 16:00:00")), + (to_timestamp("2023-01-02 16:00:00"), to_timestamp("2023-01-02 17:00:00")), + ] + + def test_missing_intervals_past_end_date_with_lookback(make_snapshot): snapshot: Snapshot = make_snapshot( # type: ignore SqlModel(