jmettraux/rufus-scheduler

Get the Last working day / weekday from the end of each month

Viktova opened this issue · 2 comments

Hello,
How can I get the last working day from the end of each month as a cron. (it's not always Friday so i cant use the Last friday from each month cron)
I don't want to include the weekends (Saturday and Sunday) but only the working/business days.

Thanks in advance!

Hello,

maybe something like:

# ...

def last_working_day?(today=Time.now)

  next_day = today + 24 * 3600
  while [ 6, 0 ].include?(next_day.wday)
    next_day += 24 * 3600         
  end

  next_day.month != today.month
end

# ...

scheduler.cron('0 12 * * *') do
  # checking every day at noon...

  if last_working_day?
    # do the job
  end
end

# ...

Closing the issue (since it's not really an issue) but not closing the conversation. Feel free to ask further.

Best regards.

Probably the fastest response ever lol, Thanks a ton n much appreciated! <3