28 lines
1 KiB
MySQL
28 lines
1 KiB
MySQL
|
|
/*
|
||
|
|
This macro returns a boolean value for dates depending on the current day of the month
|
||
|
|
|
||
|
|
Logic:
|
||
|
|
- If today is the 20th or later of the current month:
|
||
|
|
- Returns **False** for all dates within the current month.
|
||
|
|
- Returns **True** for dates before the current month.
|
||
|
|
- If today is before the 20th:
|
||
|
|
- Returns **False** for all dates within the current and previous month.
|
||
|
|
- Returns **True** for dates before the previous month.
|
||
|
|
|
||
|
|
*/
|
||
|
|
{% macro is_date_before_20th_of_previous_month(date) %}
|
||
|
|
(
|
||
|
|
case
|
||
|
|
-- If today is the 20th or later, only exclude current month
|
||
|
|
when extract(day from now()) >= 20
|
||
|
|
then
|
||
|
|
date_trunc('month', ({{ date }})::date)::date
|
||
|
|
< date_trunc('month', now())::date
|
||
|
|
-- If today is before the 20th, exclude both current and previous month
|
||
|
|
else
|
||
|
|
date_trunc('month', ({{ date }})::date)::date
|
||
|
|
< date_trunc('month', now() - interval '1 month')::date
|
||
|
|
end
|
||
|
|
)
|
||
|
|
{% endmacro %}
|