Arif Arif - 1 year ago 122
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 ?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download