private function getDateRangeFilter(): Filter
    {
        $today = new \DateTime();
        $today = $today->setTimezone(new \DateTimeZone('UTC'));

        $todayStart = $today->format('Y-m-d H:i:s 0:0:0');
        $todayEnd = $today->format('Y-m-d H:i:s 23:59:59');

        $filterNoDateRange = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new EqualsFilter('validFrom', null),
                new EqualsFilter('validUntil', null),
            ]
        );

        $filterStartedNoEndDate = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new RangeFilter('validFrom', ['lte' => $todayStart]),
                new EqualsFilter('validUntil', null),
            ]
        );

        $filterActiveNoStartDate = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new EqualsFilter('validFrom', null),
                new RangeFilter('validUntil', ['gte' => $todayEnd]),
            ]
        );

        $activeDateRangeFilter = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new RangeFilter('validFrom', ['lte' => $todayStart]),
                new RangeFilter('validUntil', ['gte' => $todayEnd]),
            ]
        );

        $dateFilter = new MultiFilter(
            MultiFilter::CONNECTION_OR,
            [
                $filterNoDateRange,
                $filterActiveNoStartDate,
                $filterStartedNoEndDate,
                $activeDateRangeFilter,
            ]
        );

        return $dateFilter;
    }
private function getDateRangeFilter(): Filter
    {
        $today = new \DateTime();
        $today = $today->setTimezone(new \DateTimeZone('UTC'));

        $todayStart = $today->format('Y-m-d H:i:s 0:0:0');
        $todayEnd = $today->format('Y-m-d H:i:s 23:59:59');

        $filterNoDateRange = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new EqualsFilter('validFrom', null),
                new EqualsFilter('validUntil', null),
            ]
        );

        $filterStartedNoEndDate = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new RangeFilter('validFrom', ['lte' => $todayStart]),
                new EqualsFilter('validUntil', null),
            ]
        );

        $filterActiveNoStartDate = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new EqualsFilter('validFrom', null),
                new RangeFilter('validUntil', ['gte' => $todayEnd]),
            ]
        );

        $activeDateRangeFilter = new MultiFilter(
            MultiFilter::CONNECTION_AND,
            [
                new RangeFilter('validFrom', ['lte' => $todayStart]),
                new RangeFilter('validUntil', ['gte' => $todayEnd]),
            ]
        );

        $dateFilter = new MultiFilter(
            MultiFilter::CONNECTION_OR,
            [
                $filterNoDateRange,
                $filterActiveNoStartDate,
                $filterStartedNoEndDate,
                $activeDateRangeFilter,
            ]
        );

        return $dateFilter;
    }
private function getDateRangeFilter ( ) : Filter { $ today = new \ DateTime ( ) ; $ today = $ today -> setTimezone ( new \ DateTimeZone ( 'UTC' ) ) ; $ todayStart = $ today -> format ( 'Y-m-d H:i:s 0:0:0' ) ; $ todayEnd = $ today -> format ( 'Y-m-d H:i:s 23:59:59' ) ; $ filterNoDateRange = new MultiFilter ( MultiFilter :: CONNECTION_AND , [ new EqualsFilter ( 'validFrom' , null ) , new EqualsFilter ( 'validUntil' , null ) , ] ) ; $ filterStartedNoEndDate = new MultiFilter ( MultiFilter :: CONNECTION_AND , [ new RangeFilter ( 'validFrom' , [ 'lte' => $ todayStart ] ) , new EqualsFilter ( 'validUntil' , null ) , ] ) ; $ filterActiveNoStartDate = new MultiFilter ( MultiFilter :: CONNECTION_AND , [ new EqualsFilter ( 'validFrom' , null ) , new RangeFilter ( 'validUntil' , [ 'gte' => $ todayEnd ] ) , ] ) ; $ activeDateRangeFilter = new MultiFilter ( MultiFilter :: CONNECTION_AND , [ new RangeFilter ( 'validFrom' , [ 'lte' => $ todayStart ] ) , new RangeFilter ( 'validUntil' , [ 'gte' => $ todayEnd ] ) , ] ) ; $ dateFilter = new MultiFilter ( MultiFilter :: CONNECTION_OR , [ $ filterNoDateRange , $ filterActiveNoStartDate , $ filterStartedNoEndDate , $ activeDateRangeFilter , ] ) ; return $ dateFilter ; }
This is the basic filter that can be added
to get only promotions valid for the current time period.
This is the basic filter that can be added to get only promotions valid for the current time period .