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 244 forks source link

every last friday of the month #170

Closed kirrg001 closed 8 years ago

kirrg001 commented 8 years ago

Hey, nice lib. I want get every last DAY of the month.

var schedule = later.parse.text('every last friday of the month', true);
console.log(later.schedule(schedule).next(10));

prints

0

Thanks!

bunkat commented 8 years ago

You want

var schedule = later.parse.text('on friday on the last day of the month')

You can verify that you string is correct by doing console.log(schedule). The error property indicates the position in the text string where an error in parsing has occurred. You want this to be -1 for a valid text string. You'll want to look at the syntax trees at https://bunkat.github.io/later/parsers.html#text for information on how to form the strings properly. It only supports a very strict syntax, not general English phrases.

kirrg001 commented 8 years ago

Hey thanks for fast response.

var schedule = later.parse.text('on friday on the last day of the month', true);
console.log(later.schedule(schedule).next(10));

[ Fri Sep 30 2016 02:00:00 GMT+0200 (CEST),
  Fri Mar 31 2017 02:00:00 GMT+0200 (CEST),
  Fri Jun 30 2017 02:00:00 GMT+0200 (CEST),
  Fri Aug 31 2018 02:00:00 GMT+0200 (CEST),
  Fri Nov 30 2018 01:00:00 GMT+0100 (CET),
  Fri May 31 2019 02:00:00 GMT+0200 (CEST),
  Fri Jan 31 2020 01:00:00 GMT+0100 (CET),
  Fri Jul 31 2020 02:00:00 GMT+0200 (CEST),
  Fri Apr 30 2021 02:00:00 GMT+0200 (CEST),
  Fri Dec 31 2021 01:00:00 GMT+0100 (CET) ]
bunkat commented 8 years ago

Sorry it's late here. You want day instance, not day of the month.

var schedule = later.parse.text('on friday on the last day instance');
kirrg001 commented 8 years ago

works!