| @@ 20-41 (lines=22) @@ | ||
| 17 | * For the format, see: |
|
| 18 | * http://php.net/manual/en/datetime.createfromformat.php |
|
| 19 | */ |
|
| 20 | class OlderThan extends AbstractDateTimeComparator { |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Holds whether to parse the parameters as \DateTimes so the child class |
|
| 24 | * can decide. |
|
| 25 | */ |
|
| 26 | protected $parseParametersAsDateTimes = false; |
|
| 27 | ||
| 28 | /** |
|
| 29 | * Holds the type of the validator. |
|
| 30 | */ |
|
| 31 | protected $type = 'olderThan'; |
|
| 32 | ||
| 33 | /** |
|
| 34 | * {@inheritdoc} |
|
| 35 | */ |
|
| 36 | protected function isValidComparison(\DateTime $date, array $datetimes, array $parameters) { |
|
| 37 | $now = new \DateTime(); |
|
| 38 | return $now->getTimestamp() - $date->getTimestamp() > $parameters[0]; |
|
| 39 | } |
|
| 40 | ||
| 41 | } |
|
| 42 | ||
| @@ 20-41 (lines=22) @@ | ||
| 17 | * For the format, see: |
|
| 18 | * http://php.net/manual/en/datetime.createfromformat.php |
|
| 19 | */ |
|
| 20 | class YoungerThan extends AbstractDateTimeComparator { |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Holds whether to parse the parameters as \DateTimes so the child class |
|
| 24 | * can decide. |
|
| 25 | */ |
|
| 26 | protected $parseParametersAsDateTimes = false; |
|
| 27 | ||
| 28 | /** |
|
| 29 | * Holds the type of the validator. |
|
| 30 | */ |
|
| 31 | protected $type = 'youngerThan'; |
|
| 32 | ||
| 33 | /** |
|
| 34 | * {@inheritdoc} |
|
| 35 | */ |
|
| 36 | protected function isValidComparison(\DateTime $date, array $datetimes, array $parameters) { |
|
| 37 | $now = new \DateTime(); |
|
| 38 | return $now->getTimestamp() - $date->getTimestamp() < $parameters[0]; |
|
| 39 | } |
|
| 40 | ||
| 41 | } |
|
| 42 | ||