Created
September 22, 2015 10:05
-
-
Save vzaremba/776265689f3b704aa859 to your computer and use it in GitHub Desktop.
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
private def period_cond(t_alias = 'f', t_column = 'created_at') | |
beginning_date, end_date = | |
case options.period | |
when 'this_week' | |
[Date.current.beginning_of_week.to_date, Date.current.to_date] | |
when 'this_month' | |
[Date.current.beginning_of_month.to_date, Date.current.to_date] | |
when 'this_quarter' | |
[Date.current.beginning_of_quarter.to_date, Date.current.to_date] | |
when 'this_year' | |
[Date.current.beginning_of_year.to_date, Date.current.to_date] | |
when 'last_week' | |
[1.week.ago.beginning_of_week.to_date, 1.week.ago.end_of_week.to_date] | |
when 'last_month' | |
[1.month.ago.beginning_of_month.to_date, 1.month.ago.end_of_month.to_date] | |
when 'last_quarter' | |
[(Date.current.beginning_of_quarter - 3.months).to_date, (Date.current.beginning_of_quarter - 1.day).to_date] | |
when 'last_year' | |
[1.year.ago.beginning_of_year.to_date, 1.year.ago.end_of_year.to_date] | |
end | |
period_cond_sql(beginning_date, end_date, t_alias, t_column) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment