开发者

Every 4th Monday?

开发者 https://www.devze.com 2023-03-14 23:39 出处:网络
I need a reminder every 4th Monday (= every 28 days) from the Monday I start co开发者_开发知识库unting. So I thought I can have ruby script

I need a reminder every 4th Monday (= every 28 days) from the Monday I start co开发者_开发知识库unting. So I thought I can have ruby script

  • to send me an email ( I know how so do this part )
  • every 4th Monday , not every 4th Monday of a month. ( <--- how to code this bit in ruby? )

I will run the ruby scrip via cron every Monday ....


Assuming you've already determined that it's a Monday, then count the days since the beginning of the year (yday()), modulus by 28, and see if the result is in 22 and 27 (inclusive) or is 0.

Given a starting (initial run) date, you can just use step(28) to get the next date and if it equals the current date, run and then store that for your next run.

As an aside, if you had meant the 4th Monday in the month, check the current day of the Month, and if it's between the 22nd and 28th of the month, you're in the fourth occurance of that day of the week that month.


Give this a try. Whenever is cron for ruby.


This gentleman calculated the first week of the month, if you're running your script every Monday by cron, then you only need to find out if it is the 4th week of the month by ruby.

http://www.ruby-forum.com/topic/95015


I think you should use these two ruby gems:

To set a cron job -> WHENEVER - https://github.com/javan/whenever

gem install whenever

To send an email (obviously) -> GMAIL - https://github.com/nu7hatch/gmail gem install gmail

Good Luck :D

0

精彩评论

暂无评论...
验证码 换一张
取 消