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 X days occurances #192

Open arnthorsnaer opened 7 years ago

arnthorsnaer commented 7 years ago

Assuming any day, for example today's date. How do I create a schedule with occurances on every 9 days from today?

This sounds like a pretty basic question, but I've been reading the docs and trying some code and can't figure this out...

MaxMem commented 7 years ago

It's not meant to do that. A standard Javascript timer would be better for that, since execution is relative to the time it was set.

arnthorsnaer commented 7 years ago

@MaxMem thanks for comment.

The thing is that I have a few scheduling options available to the user, and as it stands they are all implemented with the later.js and the schedule data structure. Having to use completely new code and new data structures to manage what is essentially a list of occurrences seems pretty messy.

Anyways, I can't use a timer for this since this will be evaluated somewhere else.

Generating the list of dates is pretty easy - adding the dates to the schedules datastructure is the tricky part.

I'm wondering if I could write a custom modifier to achive this.

dsullivan7 commented 7 years ago

I think a every(9).day() time period pattern would make a lot of sense. I feel like a custom modifier could be written that increments the day value of a Date by 1. A lot of logic would need to be written to handle time periods between months, between years, in leap years, etc... But I don't think it's out of the realm of possibility. This would be something like .recur().every(9, "days") in moment-recur