Arif Arif - 9 months ago 72
Ruby Question

Rails 4: Check if today is sunday, 15th of month or last day of month

A sidekiq worker sending PDF attachment in emails to clients. The worker runs daily checking if its Sunday then sends weekly report, if today is 15th of month then Bi-monthly report and if last day of month then monthly report. The condition looks something like this:

if sunday?
# send weekly
elsif 15th of month
# send Bi-monthly
elsif last_day_of_month
# send Monthly

How to check if its sunday, 15th of month and last day of month ?


Rails has many interesting methods for this kind of date calculations:

today =

if today.sunday?
  # send weekly
elsif == 15
  # send bi-monthly
elsif today == today.end_of_month
  # send monthly