-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from calogica/feature/add-dynamic-date-support-…
…to-get_base_dates Update base date logic to allow to dynamic date ranges
- Loading branch information
Showing
1 changed file
with
15 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
{% macro get_base_dates(start_date, end_date) %} | ||
{% macro get_base_dates(start_date=None, end_date=None, n_dateparts=None, datepart=None) %} | ||
with date_spine as | ||
( | ||
{% if start_date and end_date %} | ||
{%- set start_date="cast('" ~ start_date ~ "' as datetime)" -%} | ||
{%- set end_date="cast('" ~ end_date ~ "' as datetime)" -%} | ||
|
||
{% elif n_dateparts and datepart %} | ||
|
||
{%- set start_date = dbt_utils.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%} | ||
{%- set end_date = dbt_date.tomorrow() -%} | ||
{% endif %} | ||
|
||
{{ dbt_utils.date_spine( | ||
datepart="day", | ||
start_date="cast('" ~ start_date ~ "' as datetime)", | ||
end_date="cast('" ~ end_date ~ "' as datetime)", | ||
start_date=start_date, | ||
end_date=end_date, | ||
) | ||
}} | ||
|
||
) | ||
select | ||
d.date_day | ||
date(d.date_day) as date_day | ||
from | ||
date_spine d | ||
{% endmacro %} |