Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlmesh/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions tests/core/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down