On Sat, Nov 22, 2008 at 10:26 AM, Jeffrey Pearson <[EMAIL PROTECTED]
> wrote:
> 1) Figure out the dates
> 2) Display them on the web page. I dont want this stored in the db so
> I dont want to add it to my model.
I had this same problem.
Try something like this:
Create a file in config/initializers called 'time.rb'
In there put something like this:
class Time
def Time.last_monday
today = Time.now
case
when today.wday == 1
days_since_monday = 7
when today.wday > 1
days_since_monday = today.wday - 1
when today.wday == 0
days_since_monday = 6
end
today - days_since_monday.day
end
end
Now, once you restart your app, from anywhere you can call Time.last_monday
and get a time object with the right date.
Then you can do:
Time.last_monday + 1.day #=> Tue
Time.last_monday + 2.days #=> Wed
Time.last_monday + 3.days #=> Thu
Time.last_monday + 4.days #=> Fri
Time.last_monday + 5.days #=> Sat
Time.last_monday + 6.days #=> Sun
I'll leave modifying the class to you to make Time.last_sunday
The way I figured this out was looking in the Rails source code in
ActiveSupport's time extensions
HTH, Mikel
--
http://lindsaar.net/
Rails, RSpec and Life blog....
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---