Exception
1 day ago
SpecificationFactory
1 day ago
AggregateSpecification.php
1 day ago
AndSpecification.php
1 day ago
CollectionOperators.php
1 day ago
CollectionSpecification.php
1 day ago
ComparisonOperators.php
1 day ago
ComparisonSpecification.php
1 day ago
CompositeSpecification.php
1 day ago
ContainsSpecification.php
1 day ago
Context.php
1 day ago
ContextAwareSpecification.php
1 day ago
DateComparisonSpecification.php
1 day ago
DateOperators.php
1 day ago
DateRangeSpecification.php
1 day ago
DateRelativeDaysSpecification.php
1 day ago
DateRelativeDeductedSpecification.php
1 day ago
DateSpecification.php
1 day ago
DateTimeFactory.php
1 day ago
DateTrait.php
1 day ago
EndsWithSpecification.php
1 day ago
FactSpecification.php
1 day ago
FactTrait.php
1 day ago
FloatComparisonSpecification.php
1 day ago
FloatRangeSpecification.php
1 day ago
IntegerComparisonSpecification.php
1 day ago
IntegerRangeSpecification.php
1 day ago
NotSpecification.php
1 day ago
NullSpecification.php
1 day ago
OperatorExpression.php
1 day ago
OrSpecification.php
1 day ago
RangeOperators.php
1 day ago
RangeSpecification.php
1 day ago
Specification.php
1 day ago
SpecificationFactory.php
1 day ago
StartsWithSpecification.php
1 day ago
StringComparisonSpecification.php
1 day ago
StringMatchSpecification.php
1 day ago
StringOperators.php
1 day ago
Type.php
1 day ago
TypeSpecification.php
1 day ago
TypeTrait.php
1 day ago
Types.php
1 day ago
DateRangeSpecification.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Expression; |
| 6 | |
| 7 | use AC\Expression\Exception\InvalidDateFormatException; |
| 8 | use DateTimeZone; |
| 9 | |
| 10 | class DateRangeSpecification extends RangeSpecification implements TypeSpecification, DateSpecification |
| 11 | { |
| 12 | use DateTrait; |
| 13 | use TypeTrait; |
| 14 | |
| 15 | /** |
| 16 | * @throws InvalidDateFormatException |
| 17 | */ |
| 18 | public function __construct( |
| 19 | string $operator, |
| 20 | string $a, |
| 21 | string $b, |
| 22 | ?string $format = null, |
| 23 | ?DateTimeZone $timezone = null |
| 24 | ) { |
| 25 | parent::__construct( |
| 26 | $operator, |
| 27 | DateTimeFactory::create_from_format($a, $format, $timezone)->getTimestamp(), |
| 28 | DateTimeFactory::create_from_format($b, $format, $timezone)->getTimestamp() |
| 29 | ); |
| 30 | |
| 31 | $this->format = $format; |
| 32 | $this->timezone = $timezone; |
| 33 | $this->type = Types::DATE; |
| 34 | } |
| 35 | |
| 36 | public function is_satisfied_by($value): bool |
| 37 | { |
| 38 | return parent::is_satisfied_by( |
| 39 | $this->create_date_from_value((string)$value)->getTimestamp() |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | public function export(): array |
| 44 | { |
| 45 | return array_merge( |
| 46 | parent::export(), |
| 47 | $this->export_type(), |
| 48 | $this->export_date() |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | } |
| 53 |