Skip to content

Commit

Permalink
Merge 6cb61c6 into 58a8e1e
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkScorpion committed Nov 10, 2017
2 parents 58a8e1e + 6cb61c6 commit 06d6589
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/convert-expression/index.js
Expand Up @@ -15,6 +15,10 @@ module.exports = (function() {
return expressions;
}

function removeSpaces(str) {
return str.replace(/\s{2,}/g, ' ').trim();
}

/*
* The node-cron core allows only numbers (including multiple numbers e.g 1,2).
* This module is going to translate the month names, week day names and ranges
Expand All @@ -33,7 +37,7 @@ module.exports = (function() {
* - Will be translated to 1,2,3,4,5 * * * *
*/
function interprete(expression){
var expressions = expression.split(' ');
var expressions = removeSpaces(expression).split(' ');
expressions = appendSeccondExpression(expressions);
expressions[4] = monthNamesConversion(expressions[4]);
expressions[5] = weekDayNamesConversion(expressions[5]);
Expand All @@ -43,5 +47,6 @@ module.exports = (function() {

return expressions.join(' ');
}

return interprete;
}());
16 changes: 16 additions & 0 deletions test/validate-taks-schaduling-test.js
Expand Up @@ -20,4 +20,20 @@ describe('validate cron on task schaduling', function(){
expect(e).to.equal('65 is a invalid expression for minute');
});
});

it('validate some spaces in task string', function(){
var result = cron.validate('5 * * * *');
expect(result).to.equal(true);
});

it('multiple spaces in task string', function(){
var result = cron.validate('5 * * * *');
expect(result).to.equal(true);
});

it('spaces in begin and end of string', function(){
var result = cron.validate(' 5 * * * * ');
expect(result).to.equal(true);
});

});

0 comments on commit 06d6589

Please sign in to comment.