Working with a Rails 3 application. Given a DateTime, I need to produce the Datetime for the previous Sunday. If the DateTime is a Sunday, then I want that Sunday itself back. Here’s some examples:
November 7, 2011 => November 6, 2011 November 6, 2011 => November 6, 2011 November 5, 2011 => October 30, 2011
Any ideas? I’m a bit stuck.
…but this is so easy, there’s no reason to monkey patch it into the class 🙂
The
wday(weekday) will be0for any Sunday, and so no change to the date will take place.