Skip to content

Commit 4582af0

Browse files
authored
Merge pull request #15 from adhocore/14-expr-delimiter
14 expr delimiter
2 parents 0c3405b + 6c8b8ae commit 4582af0

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
language: php
22

33
php:
4-
- 5.4
5-
- 5.5
64
- 5.6
75
- 7.0
86
- 7.1
97
- 7.2
8+
- 7.3
109
- nightly
1110

1211
matrix:

src/Expression.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ public function filter(array $jobs, $time = null)
173173
protected function process($expr, $time)
174174
{
175175
$expr = $this->normalizeExpr($expr);
176-
$expr = \str_ireplace(\array_keys(static::$literals), \array_values(static::$literals), $expr);
177-
$expr = \explode(' ', $expr);
176+
$expr = \preg_split('~\s+~', $expr); // 14
178177

179178
if (\count($expr) < 5 || \count($expr) > 6) {
180179
throw new \UnexpectedValueException(
@@ -203,10 +202,16 @@ protected function normalizeTime($time)
203202

204203
protected function normalizeExpr($expr)
205204
{
205+
$expr = \trim($expr);
206+
206207
if (isset(static::$expressions[$expr])) {
207-
$expr = static::$expressions[$expr];
208+
return static::$expressions[$expr];
208209
}
209210

210-
return $expr;
211+
return \str_ireplace(
212+
\array_keys(static::$literals),
213+
\array_values(static::$literals),
214+
$expr
215+
);
211216
}
212217
}

tests/ExpressionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public function scheduleProvider()
103103

104104
['*/2 */2 * * *', '2015-08-10 21:47:27', '2015-08-10 22:00:00', false],
105105
['* * * * *', '2015-08-10 21:50:37', '2015-08-10 21:50:00', true],
106+
['* * * * * ', '2015-08-10 21:50:37', '2015-08-10 21:50:00', true],
107+
['* * * * *', '2015-08-10 21:50:37', '2015-08-10 21:50:00', true],
108+
["*\t*\t*\t*\t*", '2015-08-10 21:50:37', '2015-08-10 21:50:00', true],
109+
["*\t\t*\t\t*\t\t*\t\t*", '2015-08-10 21:50:37', '2015-08-10 21:50:00', true],
106110
['* 20,21,22 * * *', '2015-08-10 21:50:00', '2015-08-10 21:50:00', true],
107111
// Handles CSV values
108112
['* 20,22 * * *', '2015-08-10 21:50:00', '2015-08-10 22:00:00', false],

0 commit comments

Comments
 (0)