-
Notifications
You must be signed in to change notification settings - Fork 0
/
cronadd.php
162 lines (134 loc) · 7.52 KB
/
cronadd.php
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
class CombineCrons {
private $cronAdd;
public function ReturnCron($_cronBegin, $_cronAdd) {
$this->cronAdd = $_cronAdd;
$this->cronAdd = explode(" ", $this->cronAdd);
return $this->SplitCrons($_cronBegin);
}
//Set the $this->increment and explode the initial cron value
private $increment = 0;
private function AddCrons($cronStart, $timeType) {
if ($this->cronAdd[$timeType] != "*" && $cronStart != "*") {
$timeAdded;
$timesDivisible = 0;
$divisor = 0;
//Minute
if ($timeType == 0) {
$divisor = 60;
$timeAdded = (intval($cronStart) + intval($this->cronAdd[$timeType])) % $divisor;
if (((intval($cronStart) + intval($this->cronAdd[$timeType]) - $timeAdded) / $divisor) >= 1)
$this->increment = 1;
} //Hour
else if ($timeType == 1) {
$divisor = 24;
$timeAdded = (intval($cronStart) + intval($this->cronAdd[$timeType])) % $divisor;
if (((intval($cronStart) + intval($this->cronAdd[$timeType]) - $timeAdded) / $divisor) >= 1)
$this->increment = 1;
} //DotM
else if ($timeType == 2) {
$divisor = 32;
$timeAdded = (intval($cronStart) + intval($this->cronAdd[$timeType])) % $divisor;
if (((intval($cronStart) + intval($this->cronAdd[$timeType]) - $timeAdded) / $divisor) >= 1)
$this->increment = 1;
if ($timeAdded < $cronStart)
$timeAdded++; //Can't be zero
} //Month
else if ($timeType == 3) {
$divisor = 13;
$timeAdded = (intval($cronStart) + intval($this->cronAdd[$timeType])) % $divisor;
if (((intval($cronStart) + intval($this->cronAdd[$timeType]) - $timeAdded) / $divisor) >= 1)
$this->increment = 1;
if ($timeAdded < $cronStart)
$timeAdded++; //Can't be zero
} //DotW
else if ($timeType == 4) {
$divisor = 7;
$timeAdded = (intval($cronStart) + intval($this->cronAdd[$timeType])) % $divisor;
if (((intval($cronStart) + intval($this->cronAdd[$timeType]) - $timeAdded) / $divisor) >= 1)
$this->increment = 1;
}
else {
$timeAdded = intval($cronStart) + intval($this->cronAdd[$timeType]);
}
return $timeAdded;
} else {
return $cronStart;
};
}
private function SplitCrons($cronStart, $timeType=0) {
$cronStart_split = "";
if (strpos($cronStart," ") !== false) {
$cronStart_split = explode(" ", $cronStart);
$cronStart = "";
for ($count = 0; $count < count($cronStart_split); $count++) {
$cronStart = $cronStart.$this->SplitCrons($cronStart_split[$count], $count);
//echo "<div>$count: $cronStart</div>";
if ($count != (count($cronStart_split) - 1))
$cronStart = $cronStart." ";
if ($this->increment > 0) {
//Minute
if ($count == 0) {
if ($this->cronAdd[$count + 1] != "*")
$this->cronAdd[$count + 1] = intval($this->cronAdd[$count + 1]) + intval($this->increment);
else
$this->cronAdd[$count + 1] = intval($this->increment);
} //Hour
else if ($count == 1) {
if ($this->cronAdd[$count + 1] != "*" && $this->cronAdd[count($this->cronAdd) - 1] != "*") {
$this->cronAdd[$count + 1] = intval($this->cronAdd[$count + 1]) + intval($this->increment);
$this->cronAdd[count($this->cronAdd) - 1] = intval($this->cronAdd[count($this->cronAdd) - 1]) + intval($this->increment);
} else if ($this->cronAdd[$count + 1] != "*") {
$this->cronAdd[$count + 1] = intval($this->cronAdd[$count + 1]) + intval($this->increment);
$this->cronAdd[count($this->cronAdd) - 1] = intval($this->increment);
} else if ($this->cronAdd[count($this->cronAdd) - 1] != "*") {
$this->cronAdd[$count + 1] = intval($this->increment);
$this->cronAdd[count($this->cronAdd) - 1] = intval($this->cronAdd[count($this->cronAdd) - 1]) + intval($this->increment);
} else {
$this->cronAdd[$count + 1] = intval($this->increment);
$this->cronAdd[count($this->cronAdd) - 1] = intval($this->increment);
}
} //DotM
else if ($count == 2) {
if ($this->cronAdd[$count + 1] != "*")
$this->cronAdd[$count + 1] = intval($this->cronAdd[$count + 1]) + intval($this->increment);
else
$this->cronAdd[$count + 1] = intval($this->increment);
} //Month
else if ($count == 3) {
//No year to add
} //DotW
else if ($count == 4)
if ($this->cronAdd[$count - 1] != "*")
$this->cronAdd[$count - 1] = intval($this->cronAdd[$count - 1]) + intval($this->increment);
else
$this->cronAdd[$count - 1] = intval($this->increment);
};
$this->increment = 0;
};
} else if (strpos($cronStart,",") !== false) {
$cronStart = explode(",", $cronStart);
for ($count = 0; $count < count($cronStart); $count++) {
$cronStart[$count] = $this->SplitCrons($cronStart[$count], $timeType);
}
//$cronStart.sort(function (a, b) {return a - b;});
$cronStart = implode(",", $cronStart);
} else if (strpos($cronStart,"-") !== false) {
$cronStart = explode("-", $cronStart);
for ($count = 0; $count < count($cronStart); $count++) {
$cronStart[$count] = $this->SplitCrons($cronStart[$count], $timeType);
}
$cronStart = implode("-", $cronStart);
} else {
$cronStart = $this->AddCrons($cronStart, $timeType);
};
return $cronStart;
}
};
$CombineCrons = new CombineCrons();
/*$startCron = "1,2 1-2 0 0 0";
$addCron = "1 23 0 0 0";
echo "<div>$startCron</div>";
echo "<div>$addCron</div>";*/
//echo "<div>".$CombineCrons->ReturnCron($startCron, $addCron)."</div>";
?>