Skip to content

Commit

Permalink
Make comparing date segments strict. (#84)
Browse files Browse the repository at this point in the history
* Make comparing date segments strict.

* Updated CHANGELOG file.
  • Loading branch information
PabloKowalczyk authored Apr 21, 2018
1 parent 401c6c9 commit 89726a7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ thanks to [@m-hume](https://github.com/m-hume)
[@PabloKowalczyk](https://github.com/PabloKowalczyk)
- Problem with `->in(dirname)` on Windows - PR [#81](https://github.com/lavary/crunz/pull/81),
[@PabloKowalczyk](https://github.com/PabloKowalczyk)
- Task runs every minute of hour with `on()`, solves issue
[#83](https://github.com/lavary/crunz/issues/83) - PR [#84](https://github.com/lavary/crunz/pull/84)

## 1.5.1 - 2018-04-12

Expand Down
11 changes: 4 additions & 7 deletions src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,20 +377,17 @@ public function daily()
*/
public function on($date)
{

$date = date_parse($date);
$segments = array_only($date, array_flip($this->fieldsPosition));
$date = \date_parse($date);
$segments = \array_only($date, \array_flip($this->fieldsPosition));

if ($date['year']) {

$this->skip(function () use ($segments) {
return (int) date('Y') != $segments['year'];
});

}

foreach ($segments as $key => $value) {
if ($value != false) {
if ($value !== false) {
$this->spliceIntoPosition($this->fieldsPosition[$key], (int) $value);
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ public function inChangeWorkingDirectoryInBuildCommandOnUnix()
$this->assertSame('cd /tmp; php -v', $event->buildCommand());
}

/** @test */
public function onDoNotRunTaskEveryMinute()
{
$event = new Event($this->id, 'php -i');

$event->on('Thursday 8:00');

$this->assertSame('0 8 * * * *', $event->getExpression());
}

private function isWindows()
{
return DIRECTORY_SEPARATOR === '\\';
Expand Down

0 comments on commit 89726a7

Please sign in to comment.