bunkat / later

A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.
http://bunkat.github.io/later/
MIT License
2.42k stars 245 forks source link

Nth weekday of month #220

Open ricardonogues opened 6 years ago

ricardonogues commented 6 years ago

Is it possible to generate a recurrence like 'every last Friday of the month'?

vfonic commented 6 years ago

Hi @ricardonogues!

I needed the same functionality so I came up with this:

var time = date.toTimeString().split(' ')[0]; // get hour and minute (there are better ways to do this)
var sched = later.parse.recur().on(time).time();
var dayOfWeek = later.dayOfWeek.val(date); // NOTE this line might mess up your `date` instance
return later.schedule(sched.on(0).dayOfWeekCount().on(dayOfWeek).dayOfWeek());
moltar commented 4 years ago

Was trying to do the same with Renovate Bot:

before 3am on the first weekday of the month

And it seems not to be supported, yet every weekday is supported.