-
Notifications
You must be signed in to change notification settings - Fork 0
/
match-cron.js
41 lines (41 loc) · 997 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
37
38
39
40
41
function matchCron (cron,date){
let arr = cron.split(' ')
let minute = arr[0]
let hour = arr[1]
let dayOfMonth = arr[2]
let month = arr[3]
let dayWeek = arr[4]
// console.log(date.getDay()+1)
let flag = false
if(minute === '*'|| minute == date.getMinutes()){
flag = true
}else{
return false
}
if(hour === '*'|| hour == date.getHours()){
flag = true
}else{
return false
}
if(dayOfMonth === '*'|| dayOfMonth == date.getDate()){
flag = true
}else{
return false
}
if(month === '*'|| month == date.getMonth()+1){
flag = true
}else{
return false
}
if(dayWeek === '*'){
flag = true
}else if(dayWeek === 7 && date.getDay === 0){
flag = true
}else if(date.getDay !== 0 && Number(dayWeek) === date.getDay()){
flag = true
}else{
// console.log(date.getDay(),'-',dayWeek)
return false
}
return flag
}