-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmatch-cron.js
36 lines (36 loc) · 884 Bytes
/
match-cron.js
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
function matchCron(inputCron, date) {
let cron = {};
inputCron.split(" ").forEach((part, i) => {
if (part === "*") return;
switch (i) {
case 0:
cron.minute = part;
break;
case 1:
cron.hour = part;
break;
case 2:
cron.date = part;
break;
case 3:
cron.month = part;
break;
case 4:
cron.day = part;
break;
}
});
date = {
minute: date.getMinutes(),
hour: date.getHours(),
date: date.getDate(),
month: date.getMonth() + 1,
day: date.getDay(),
};
for (let key in cron) {
if (cron[key] !== date[key].toString()) {
return false;
}
}
return true;
}