def self.dates_for_time_range(range)
case range
when 'today' then [Date.today, Date.today]
when 'tomorrow' then [Date.tomorrow, Date.tomorrow]
when 'this_week' then [Date.today, 1.week.from_now.to_date]
else raise ArgumentError, "Incorrect time range: #{range}"
end
end
Which works perfectly, but trying to figure out what 'this weekend'
has proven to be a bit more difficult.
Thanks alot! This works exactly right. I modified the -2 to -3 to
include Friday. This is actually very close to what I had tried, but I
did not have the parenthesis correct. Too bad I wasted a whole day
before trying the forum.
Well there's the slightly shorter
[Date::today.monday + 5, Date::today.monday + 7]
(and you don't have to worry about whether that will do funny things
when the clocks go back and what not).
Probably overkill for this simple question but chronic so cool, I
thought I would mention it. Chronic is an incredible time parsing
library that makes parsing natural languages into time a sinch. 'next
weekend' is only the tip of the iceberg.