How to Tell if Today Is the First of the Week/Month/Year With Ruby
I had a project recently where a cron would fire early in the morning and generate stats for the previous day/week/month/year. I needed to know when it fired if today was the beginning of a new month so I could generate last month’s stats.
1234567891011
#First hour of the day:Time.now.hour==0#Beginnning of the weekTime.now.beginning_of_week==Time.now.beginning_of_hour#First day of the month Time.now.day==1&&Time.now.hour==0#First day of the yearTime.now.beginning_of_year==Time.now.beginning_of_hour