mailpoet
/
vendor
/
woocommerce
/
action-scheduler
/
lib
/
cron-expression
/
CronExpression_AbstractField.php
CronExpression.php
1 year ago
CronExpression_AbstractField.php
4 years ago
CronExpression_DayOfMonthField.php
4 years ago
CronExpression_DayOfWeekField.php
4 years ago
CronExpression_FieldFactory.php
4 years ago
CronExpression_FieldInterface.php
4 years ago
CronExpression_HoursField.php
4 years ago
CronExpression_MinutesField.php
4 years ago
CronExpression_MonthField.php
4 years ago
CronExpression_YearField.php
4 years ago
index.php
3 years ago
CronExpression_AbstractField.php
49 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) exit; |
| 3 | abstract class CronExpression_AbstractField implements CronExpression_FieldInterface |
| 4 | { |
| 5 | public function isSatisfied($dateValue, $value) |
| 6 | { |
| 7 | if ($this->isIncrementsOfRanges($value)) { |
| 8 | return $this->isInIncrementsOfRanges($dateValue, $value); |
| 9 | } elseif ($this->isRange($value)) { |
| 10 | return $this->isInRange($dateValue, $value); |
| 11 | } |
| 12 | return $value == '*' || $dateValue == $value; |
| 13 | } |
| 14 | public function isRange($value) |
| 15 | { |
| 16 | return strpos($value, '-') !== false; |
| 17 | } |
| 18 | public function isIncrementsOfRanges($value) |
| 19 | { |
| 20 | return strpos($value, '/') !== false; |
| 21 | } |
| 22 | public function isInRange($dateValue, $value) |
| 23 | { |
| 24 | $parts = array_map('trim', explode('-', $value, 2)); |
| 25 | return $dateValue >= $parts[0] && $dateValue <= $parts[1]; |
| 26 | } |
| 27 | public function isInIncrementsOfRanges($dateValue, $value) |
| 28 | { |
| 29 | $parts = array_map('trim', explode('/', $value, 2)); |
| 30 | $stepSize = isset($parts[1]) ? $parts[1] : 0; |
| 31 | if ($parts[0] == '*' || $parts[0] === '0') { |
| 32 | return (int) $dateValue % $stepSize == 0; |
| 33 | } |
| 34 | $range = explode('-', $parts[0], 2); |
| 35 | $offset = $range[0]; |
| 36 | $to = isset($range[1]) ? $range[1] : $dateValue; |
| 37 | // Ensure that the date value is within the range |
| 38 | if ($dateValue < $offset || $dateValue > $to) { |
| 39 | return false; |
| 40 | } |
| 41 | for ($i = $offset; $i <= $to; $i+= $stepSize) { |
| 42 | if ($i == $dateValue) { |
| 43 | return true; |
| 44 | } |
| 45 | } |
| 46 | return false; |
| 47 | } |
| 48 | } |
| 49 |