diff --git a/README.md b/README.md index 33feec6..47aecb4 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,11 @@ cronExp.build(); // '* * * * *' ``` +The cron values are stored with the following keys, which must match identically when getting and setting: +```JavaScript +'minute', 'hour', 'dayOfTheMonth', 'month', 'dayOfTheWeek' +``` + API includes basic getters and setters: ```JavaScript cronExp.get('minute'); diff --git a/cron-builder.js b/cron-builder.js index 6cd20fd..c5f8b99 100644 --- a/cron-builder.js +++ b/cron-builder.js @@ -41,7 +41,7 @@ var CronValidator = (function() { for (var measureOfTime in expression) { if (expression.hasOwnProperty(measureOfTime)) { - this.validateValue(measureOfTime, expression[measureOfTime]); + this.validateValue(measureOfTime, expression[measureOfTime][0]); } } }, @@ -89,6 +89,14 @@ var CronValidator = (function() { throw new Error('Invalid value; Only numbers 0-9, "-", and "*" chars are allowed'); } + if (!measureOfTime || !value) { + throw new Error('Missing arguments; Both measureOfTime and value are required arguments'); + } + + if (typeof(value) !== 'string') { + throw new Error('value argument must be a string'); + } + if (value !== '*') { // check to see if value is within range if value is not '*' if (value.indexOf('-') >= 0) { @@ -102,7 +110,6 @@ var CronValidator = (function() { throw new Error('Invalid value; top of range is not valid for "' + measureOfTime + '". Limit is ' + validatorObj[measureOfTime].max + '.'); } } else { - if (parseInt(value) < validatorObj[measureOfTime].min) { throw new Error('Invalid value; given value is not valid for "' + measureOfTime + '". Minimum value is "' + validatorObj[measureOfTime].min + '".'); } @@ -113,7 +120,6 @@ var CronValidator = (function() { } }; - return { measureOfTimeValues: MeasureOfTimeValues, validateExpression: validateExpression,