fix(core): update

This commit is contained in:
Philipp Kunz 2020-09-07 17:16:11 +00:00
parent 36bff0a70a
commit db92311daa
2 changed files with 36 additions and 8 deletions

View File

@ -44,6 +44,17 @@ tap.test('should create a valid cronJon', async (tools) => {
await done2.promise;
await done3.promise;
testCronManager.stop();
testCronManager.removeCronjob(cronJob3);
});
tap.test('runs every full minute', async (tools) => {
const done = tools.defer();
const cronJob = testCronManager.addCronjob('0 * * * * *', async () => {
done.resolve();
});
testCronManager.start();
await done.promise;
testCronManager.stop();
});
tap.start();

View File

@ -27,7 +27,7 @@ export class CronParser {
};
return findEvenMatch(startValue);
}
if (parseInt(cronPart, 10)) {
if (parseInt(cronPart, 10) || cronPart === '0') {
const match = parseInt(cronPart, 10);
return match;
}
@ -42,19 +42,36 @@ export class CronParser {
const monthExpression = cronArray[4];
const yearExpression = cronArray[5];
const currentDate = new Date();
const currentSecond = currentDate.getSeconds() + 1;
const currentMinute = currentDate.getMinutes();
const currentHour = currentDate.getHours();
const currentDay = currentDate.getDate();
const currentMonth = currentDate.getMonth();
const currentYear = currentDate.getFullYear();
let currentDate = new Date();
let currentSecond = currentDate.getSeconds() + 1;
let currentMinute = currentDate.getMinutes();
let currentHour = currentDate.getHours();
let currentDay = currentDate.getDate();
let currentMonth = currentDate.getMonth();
let currentYear = currentDate.getFullYear();
const targetSecond = this.getNextPartMatch(secondExpression, currentSecond, 59);
if (targetSecond < currentSecond) {
currentMinute = (currentMinute + 1) % 59;
}
const targetMinute = this.getNextPartMatch(minuteExpression, currentMinute, 59);
if (targetMinute < currentMinute) {
currentHour = (currentHour + 1) % 23;
}
const targetHour = this.getNextPartMatch(hourExpression, currentHour, 23);
if (targetHour < currentHour) {
currentDay = (currentDay + 1) % 30;
}
const targetDay = currentDay;
if (targetDay < currentDay) {
currentMonth = (currentMonth + 1) % 11;
}
const targetMonth = currentMonth;
if (targetMonth < currentMonth) {
currentYear = (currentYear + 1);
}
const targetYear = currentYear;
const targetDate = new Date(