Skip to content

Commit 5890046

Browse files
committedFeb 16, 2018
Add vendor directory to allow for complete release
1 parent 210f21d commit 5890046

34 files changed

+2917
-1
lines changed
 

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
vendor
21
.idea
32
composer.lock
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_style = space
16+
indent_size = 2
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Change Log
2+
3+
## [1.2.0] - 2017-01-22
4+
### Added
5+
- Added IDE, CodeSniffer, and StyleCI.IO support
6+
7+
### Changed
8+
- Switched to PSR-4 Autoloading
9+
10+
### Fixed
11+
- 0 step expressions are handled better
12+
- Fixed `DayOfMonth` validation to be more strict
13+
- Typos
14+
15+
## [1.1.0] - 2016-01-26
16+
### Added
17+
- Support for non-hourly offset timezones
18+
- Checks for valid expressions
19+
20+
### Changed
21+
- Max Iterations no longer hardcoded for `getRunDate()`
22+
- Supports DateTimeImmutable for newer PHP verions
23+
24+
### Fixed
25+
- Fixed looping bug for PHP 7 when determining the last specified weekday of a month
26+
27+
## [1.0.3] - 2013-11-23
28+
### Added
29+
- Now supports expressions with any number of extra spaces, tabs, or newlines
30+
31+
### Changed
32+
- Using static instead of self in `CronExpression::factory`
33+
34+
### Fixed
35+
- Fixes issue [#28](https://github.com/mtdowling/cron-expression/issues/28) where PHP increments of ranges were failing due to PHP casting hyphens to 0
36+
- Only set default timezone if the given $currentTime is not a DateTime instance ([#34](https://github.com/mtdowling/cron-expression/issues/34))

‎vendor/a3020/cron-expression/LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2011 Michael Dowling <mtdowling@gmail.com> and contributors
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Note: This is a fork of https://github.com/dragonmantank/cron-expression/releases/tag/v1.2.1
2+
3+
PHP Cron Expression Parser
4+
==========================
5+
6+
[![Latest Stable Version](https://poser.pugx.org/mtdowling/cron-expression/v/stable.png)](https://packagist.org/packages/mtdowling/cron-expression) [![Total Downloads](https://poser.pugx.org/mtdowling/cron-expression/downloads.png)](https://packagist.org/packages/mtdowling/cron-expression) [![Build Status](https://secure.travis-ci.org/mtdowling/cron-expression.png)](http://travis-ci.org/mtdowling/cron-expression)
7+
8+
The PHP cron expression parser can parse a CRON expression, determine if it is
9+
due to run, calculate the next run date of the expression, and calculate the previous
10+
run date of the expression. You can calculate dates far into the future or past by
11+
skipping n number of matching dates.
12+
13+
The parser can handle increments of ranges (e.g. */12, 2-59/3), intervals (e.g. 0-9),
14+
lists (e.g. 1,2,3), W to find the nearest weekday for a given day of the month, L to
15+
find the last day of the month, L to find the last given weekday of a month, and hash
16+
(#) to find the nth weekday of a given month.
17+
18+
Installing
19+
==========
20+
21+
Add the dependency to your project:
22+
23+
```bash
24+
composer require a3020/cron-expression
25+
```
26+
27+
Usage
28+
=====
29+
```php
30+
<?php
31+
32+
require_once '/vendor/autoload.php';
33+
34+
// Works with predefined scheduling definitions
35+
$cron = Cron\CronExpression::factory('@daily');
36+
$cron->isDue();
37+
echo $cron->getNextRunDate()->format('Y-m-d H:i:s');
38+
echo $cron->getPreviousRunDate()->format('Y-m-d H:i:s');
39+
40+
// Works with complex expressions
41+
$cron = Cron\CronExpression::factory('3-59/15 2,6-12 */15 1 2-5');
42+
echo $cron->getNextRunDate()->format('Y-m-d H:i:s');
43+
44+
// Calculate a run date two iterations into the future
45+
$cron = Cron\CronExpression::factory('@daily');
46+
echo $cron->getNextRunDate(null, 2)->format('Y-m-d H:i:s');
47+
48+
// Calculate a run date relative to a specific time
49+
$cron = Cron\CronExpression::factory('@monthly');
50+
echo $cron->getNextRunDate('2010-01-12 00:00:00')->format('Y-m-d H:i:s');
51+
```
52+
53+
CRON Expressions
54+
================
55+
56+
A CRON expression is a string representing the schedule for a particular command to execute. The parts of a CRON schedule are as follows:
57+
58+
* * * * * *
59+
- - - - - -
60+
| | | | | |
61+
| | | | | + year [optional]
62+
| | | | +----- day of week (0 - 7) (Sunday=0 or 7)
63+
| | | +---------- month (1 - 12)
64+
| | +--------------- day of month (1 - 31)
65+
| +-------------------- hour (0 - 23)
66+
+------------------------- min (0 - 59)
67+
68+
Requirements
69+
============
70+
71+
- PHP 5.6+
72+
- PHPUnit is required to run the unit tests
73+
- Composer is required to run the unit tests
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "a3020/cron-expression",
3+
"type": "library",
4+
"description": "CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due",
5+
"keywords": ["cron", "schedule"],
6+
"license": "MIT",
7+
"authors": [{
8+
"name": "Michael Dowling",
9+
"email": "mtdowling@gmail.com",
10+
"homepage": "https://github.com/mtdowling"
11+
}],
12+
"require": {
13+
"php": ">=5.6"
14+
},
15+
"require-dev": {
16+
"phpunit/phpunit": "~4.0|~5.0"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"Cron\\": "src/Cron/"
21+
}
22+
},
23+
"autoload-dev": {
24+
"psr-4": {
25+
"Tests\\": "tests/Cron/"
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
3+
namespace Cron;
4+
5+
/**
6+
* Abstract CRON expression field
7+
*/
8+
abstract class AbstractField implements FieldInterface
9+
{
10+
/**
11+
* Check to see if a field is satisfied by a value
12+
*
13+
* @param string $dateValue Date value to check
14+
* @param string $value Value to test
15+
*
16+
* @return bool
17+
*/
18+
public function isSatisfied($dateValue, $value)
19+
{
20+
if ($this->isIncrementsOfRanges($value)) {
21+
return $this->isInIncrementsOfRanges($dateValue, $value);
22+
} elseif ($this->isRange($value)) {
23+
return $this->isInRange($dateValue, $value);
24+
}
25+
26+
return $value == '*' || $dateValue == $value;
27+
}
28+
29+
/**
30+
* Check if a value is a range
31+
*
32+
* @param string $value Value to test
33+
*
34+
* @return bool
35+
*/
36+
public function isRange($value)
37+
{
38+
return strpos($value, '-') !== false;
39+
}
40+
41+
/**
42+
* Check if a value is an increments of ranges
43+
*
44+
* @param string $value Value to test
45+
*
46+
* @return bool
47+
*/
48+
public function isIncrementsOfRanges($value)
49+
{
50+
return strpos($value, '/') !== false;
51+
}
52+
53+
/**
54+
* Test if a value is within a range
55+
*
56+
* @param string $dateValue Set date value
57+
* @param string $value Value to test
58+
*
59+
* @return bool
60+
*/
61+
public function isInRange($dateValue, $value)
62+
{
63+
$parts = array_map('trim', explode('-', $value, 2));
64+
65+
return $dateValue >= $parts[0] && $dateValue <= $parts[1];
66+
}
67+
68+
/**
69+
* Test if a value is within an increments of ranges (offset[-to]/step size)
70+
*
71+
* @param string $dateValue Set date value
72+
* @param string $value Value to test
73+
*
74+
* @return bool
75+
*/
76+
public function isInIncrementsOfRanges($dateValue, $value)
77+
{
78+
$parts = array_map('trim', explode('/', $value, 2));
79+
$stepSize = isset($parts[1]) ? (int) $parts[1] : 0;
80+
81+
if ($stepSize === 0) {
82+
return false;
83+
}
84+
85+
if (($parts[0] == '*' || $parts[0] === '0')) {
86+
return (int) $dateValue % $stepSize == 0;
87+
}
88+
89+
$range = explode('-', $parts[0], 2);
90+
$offset = $range[0];
91+
$to = isset($range[1]) ? $range[1] : $dateValue;
92+
// Ensure that the date value is within the range
93+
if ($dateValue < $offset || $dateValue > $to) {
94+
return false;
95+
}
96+
97+
if ($dateValue > $offset && 0 === $stepSize) {
98+
return false;
99+
}
100+
101+
for ($i = $offset; $i <= $to; $i+= $stepSize) {
102+
if ($i == $dateValue) {
103+
return true;
104+
}
105+
}
106+
107+
return false;
108+
}
109+
110+
/**
111+
* Returns a range of values for the given cron expression
112+
*
113+
* @param string $expression The expression to evaluate
114+
* @param int $max Maximum offset for range
115+
*
116+
* @return array
117+
*/
118+
public function getRangeForExpression($expression, $max)
119+
{
120+
$values = array();
121+
122+
if ($this->isRange($expression) || $this->isIncrementsOfRanges($expression)) {
123+
if (!$this->isIncrementsOfRanges($expression)) {
124+
list ($offset, $to) = explode('-', $expression);
125+
$stepSize = 1;
126+
}
127+
else {
128+
$range = array_map('trim', explode('/', $expression, 2));
129+
$stepSize = isset($range[1]) ? $range[1] : 0;
130+
$range = $range[0];
131+
$range = explode('-', $range, 2);
132+
$offset = $range[0];
133+
$to = isset($range[1]) ? $range[1] : $max;
134+
}
135+
$offset = $offset == '*' ? 0 : $offset;
136+
for ($i = $offset; $i <= $to; $i += $stepSize) {
137+
$values[] = $i;
138+
}
139+
sort($values);
140+
}
141+
else {
142+
$values = array($expression);
143+
}
144+
145+
return $values;
146+
}
147+
148+
}

0 commit comments

Comments
 (0)
Please sign in to comment.