Re: TimeRange ''this weekend''

Frederick Cheung
Mon, 19 May 2008 16:39:40 -0000

On 19 May 2008, at 17:24, AndyV wrote:

>
> I''m sure Fred will have a better way of attacking this but
something
> like this should work:
>
> [(1.week.from_now.beginning_of_week-2.days).to_date,
> 1.week.from_now.beginning_of_week.to_date]

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).

Fred
>
>
> On May 19, 11:25 am, Laughlink
<m...-Pd2240bJ1K0yaJ3wHwELyQ@public.gmane.org> wrote:
>> How would one calculate ''this weekend''?
>>
>> In my event model I have:
>>
>>  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.
> >