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

Every Issue #204

Open willin opened 7 years ago

willin commented 7 years ago

N < 30

console.log(JSON.stringify(later.parse.recur().every(10).second(), null, 2));
{
  "schedules": [
    {
      "s": [
        0,
        10,
        20,
        30,
        40,
        50
      ]
    }
  ],
  "exceptions": []
}

N > 30

console.log(JSON.stringify(later.parse.recur().every(45).second(), null, 2));
{
  "schedules": [
    {
      "s": [
        0,
        45
      ]
    }
  ],
  "exceptions": []
}

N >= 60

console.log(JSON.stringify(later.parse.recur().every(75).second(), null, 2));
{
  "schedules": [
    {
      "s": [
        0
      ]
    }
  ],
  "exceptions": []
}

e.g. how to set a task run every 90 seconds?

bunkat commented 7 years ago

Short answer is that you don't. Later is a very basic constraint solver where you create a schedule object that defines which times Later should consider valid. You do this by defining valid values for each of the different constraint types. Later then searches for a time that meets all of the constraints.

For example, telling Later that seconds [0, 10, 20, 30, 40, 50] are valid means Later will consider any time with those particular seconds valid. So 9:20:00, 13:29:40, etc. You can get fancier by adding more constraints like minutes [0, 15]. Now times like 10:00:10 and 4:15:50 would be valid. In your example, since 90 is not a valid seconds value, it's ignored.

If you just need to run a task every 90 seconds, just use the default interval function instead of Later. Later was meant for scheduling tasks at the human time scale (every 4th friday at 11am type stuff).