Reputation: 994
I need to find a way to check if a post was posted after a certain date. I know I can use Time.parse to convert the date stored in the database under the column created_at to a ruby formated date. However from there on I am stuck.
I need to check if the date is newer than the most recent passed Monday at midnight. I know I can use regular comparative elements such as > and <= to compare dates. So I just need to find a way get the the date of the most recent Monday that has already passed.
Please let me know if anything is not clear enough.
Thank you.
Upvotes: 3
Views: 299
Reputation: 4226
To get the date of the most recent Monday that has already passed, you could do something like this:
Date.today.beginning_of_week(:monday)
# => Mon, Aug 10 2015
You can use this to check if the provided date is more recent than the previously passed Monday, or any day of the week really:
def is_more_recent(date, day)
date > Date.today.beginning_of_week(day.to_sym)
end
is_more_recent(Date.today, :monday)
# => true
Hope it helps!
Upvotes: 2