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

dayOfWeek schedule different from crons #78

Open akagomez opened 9 years ago

akagomez commented 9 years ago

I used Later's dayOfWeek to populate a cron string that Later would then parse. The result was always off by one day because of the differing dayOfWeek definitions. Maybe there should be a note in the documentation?

Later.js:

Days of a week, from 1 to 7. Specify 0 for the last day of the week (Saturday). http://bunkat.github.io/later/time-periods.html#day-of-week

Sun: 1, Mon: 2, Tues: 3, Wed: 4, Thur: 5, Fri: 6, Sat: 0/7

Cron:

day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0) http://en.wikipedia.org/wiki/Cron#Predefined_scheduling_definitions

Sun: 0/7, Mon: 1, Tues: 2, Wed: 3, Thur: 4, Fri: 5, Sat: 6
bunkat commented 9 years ago

Yes, I can definitely add a note. This was an unfortunate arbitrary choice that was made when I first wrote the library that I don't think I can change at this point. Sorry for the confusion.

RangerMauve commented 9 years ago

Does this mean that the cron parser also has this problem?

bunkat commented 9 years ago

No, the parser correctly translates the cron value to Later (cron -> later). This issue is a case of using Later functions to populate a cron string (later -> cron) which produces the undesired result.

igorhart commented 9 years ago

Hello,

First off, later.js is just perfect! It also has one of the best documentations I had pleasure to read in my life.

I have a question regarding the parsing functionality. How should I go about "later -> cron" ?

What I am trying to do is to provide backend guys with both "cron" and "text" formats. Then, they would use the "cron" format to setup cron jobs, based on changes made by users through the app. The "text" format would be used for both user input and schedule label. Ideally, we would just store the "cron" format" and parse it to "text" for users.

Somewhere in documentation you mentioned that "cron" format is limited because it can't handle composite schedules and exceptions. How about always returning an array of "cron"s when going later -> "cron"? And similarly, make parser read array of "cron"s when going the other way, to "composite" them? (or maybe even object with schedules and exceptions).

Thanks, Igor

bunkat commented 9 years ago

The problem that you will run into is that Later is a superset of Cron. It supports many more time periods (including custom ones) that cannot be translated to Cron. Therefore, if you want to go from Later to Cron you will need to select the subset of functionality that you want to support and write converters for it. Because this subset will be different for everyone, I don't intend on ever supporting a Later -> Cron conversion in the library itself.

igorhart commented 9 years ago

Thanks for quick answer.

My knowledge about cron is very limited. Could you push me in a right direction of where should I start with converter's logic? I would love to create such converter, mostly because this is the last missing piece of later.js for what I need.

igorhart commented 9 years ago

Hello everyone,

I am back with angular module doing later.js to Quartz Cron conversion.

Few things to note:

Code here

Hope someone will find it helpful. Good luck!

akagomez commented 8 years ago

@bunkat Has this been noted in the docs? If so I'll close this issue.

Also, could this issue be worked around with custom time periods? https://bunkat.github.io/later/time-periods.html#custom