Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid cron still returns array of schedules #174

Closed
ghost opened this issue Jul 22, 2016 · 2 comments
Closed

Invalid cron still returns array of schedules #174

ghost opened this issue Jul 22, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 22, 2016

Hi guys am curious is there anyway to validate and ensure cron supported by later js is valid before calling the parse.cron function

var later = require('later');
var cron = "AAAAAAAAAAAAAAA";

var enableSeconds = true;
var schedule = later.parse.cron(cron, enableSeconds);
var futureSchedule = later.schedule(schedule).next(5);

console.log(futureSchedule);

Above seems to return a valid schedule of current time, which is not valid based on the passed in cron expression

[ Fri Jul 22 2016 17:58:20 GMT+0800
  Fri Jul 22 2016 17:58:21 GMT+0800
  Fri Jul 22 2016 17:58:22 GMT+0800
  Fri Jul 22 2016 17:58:23 GMT+0800
  Fri Jul 22 2016 17:58:24 GMT+0800]

@bunkat
Copy link
Owner

bunkat commented Jul 22, 2016

The only way at the moment is to look and see if schedule.schedules is empty. If it's empty then nothing was parsed from the cron statement. There are other cron syntax checking libraries available that might fit your need.

@bunkat bunkat closed this as completed Jul 22, 2016
@ghost
Copy link
Author

ghost commented Jul 23, 2016

Am not sure what you mean by schedule.schedules shouldnt be empty. it always returns non empty array


[ { s:
     [ null,
       1,
       2,
       3,
       4,
       5,
       6,
       7,
       8,
       9,
       10,
       11,
       12,
       13,
       14,
       15,
       16,
       17,
       18,
       19,
       20,
       21,
       22,
       23,
       24,
       25,
       26,
       27,
       28,
       29,
       30,
       31,
       32,
       33,
       34,
       35,
       36,
       37,
       38,
       39,
       40,
       41,
       42,
       43,
       44,
       45,
       46,
       47,
       48,
       49,
       50,
       51,
       52,
       53,
       54,
       55,
       56,
       57,
       58,
       59 ] } ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant