Given a string with day name, i.e. "Wednesday", how can I get a Time object representing that day within the current week (Monday – Sunday)?
So for example, if the current day is Tuesday 29 May, and the string is "Monday", the time object should represent Monday 28 May. If the string is "Friday", it should be Friday 1 June.
Whereas if the current day is Tuesday 5 June, and the string is "Monday", the time object should represent Monday 4 June. If the string is "Friday", it should be Friday 8 June.
I am using Rails 3.2.0 and Ruby 1.9.2.
There is a pretty handy gem for these types of textual date references called
Chronic:http://chronic.rubyforge.org/
For your purpose you could use the
"this week"reference:..which should work pretty much as expected.