sub example

/** * @param array<string> $mediaIds * * @return array<string> */
    private function filterOutNewMedia(array $mediaIds, int $gracePeriodDays): array
    {
        if ($gracePeriodDays === 0) {
            return $mediaIds;
        }

        $threeDaysAgo = (new \DateTime())->sub(new \DateInterval(sprintf('P%dD', $gracePeriodDays)));
        $rangeFilter = new RangeFilter('uploadedAt', ['lt' => $threeDaysAgo->format(Defaults::STORAGE_DATE_TIME_FORMAT)]);

        $criteria = new Criteria($mediaIds);
        $criteria->addFilter($rangeFilter);

        /** @var array<string> $ids */
        $ids = $this->mediaRepo->searchIds($criteria, Context::createDefaultContext())->getIds();

        return $ids;
    }

    


    public function handle(ConditionInterface $condition, QueryBuilder $query): void
    {
        $this->addCondition($condition$query);
    }

    private function addCondition(NotOrderedInLastDaysCondition $condition, QueryBuilder $query): void
    {
        $query->andWhere('customer.last_order_time <= :NotOrderedInLastDaysCondition');
        $date = new DateTime();
        $date->sub(new DateInterval('P' . $condition->getLastDays() . 'D'));
        $query->setParameter(':NotOrderedInLastDaysCondition', $date->format('Y-m-d H:i:s'));
    }
}
public function testGetCustomerRecoveryExpired(): void
    {
        $customerRecoveryRoute = $this->getContainer()->get(CustomerRecoveryIsExpiredRoute::class);

        $token = Uuid::randomHex();

        $context = $this->getContainer()->get(SalesChannelContextFactory::class)->create($token, TestDefaults::SALES_CHANNEL);

        $this->getContainer()->get(Connection::class)->update(
            'customer_recovery',
            [
                'created_at' => (new \DateTime())->sub(new \DateInterval('PT3H'))->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ],
            [
                'id' => Uuid::fromHexToBytes($this->hashId),
            ]
        );

        $customerRecoveryResponse = $customerRecoveryRoute->load(new RequestDataBag(['hash' => $this->hash])$context);

        static::assertTrue($customerRecoveryResponse->isExpired());
    }
}
QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $this->addCondition($condition$query);
    }

    private function addCondition(CreateDateCondition $condition, QueryBuilder $query): void
    {
        $date = new DateTime();
        $intervalSpec = 'P' . $condition->getDays() . 'D';
        $interval = new DateInterval($intervalSpec);
        $date->sub($interval);

        $suffix = md5(json_encode($condition, JSON_THROW_ON_ERROR));
        $key = ':createDateFrom' . $suffix;

        $query->andWhere('product.datum >= ' . $key)
            ->setParameter($key$date->format('Y-m-d'));
    }
}
return $totalCount;
    }

    /** * Helper to get the from date in the right format */
    private function getFromDate(): DateTime
    {
        $fromDate = $this->Request()->getParam('fromDate');
        if (empty($fromDate)) {
            $fromDate = new DateTime();
            $fromDate = $fromDate->sub(new DateInterval('P1Y'));
        } else {
            $fromDate = new DateTime($fromDate);
        }

        return $fromDate;
    }

    /** * helper to get the to date in the right format */
    private function getToDate(): DateTime
    {


    /** * Gets the turnover and visitors amount for the * chart and the grid in the "Turnover - Yesterday and today"-widget. * * @return void */
    public function getTurnOverVisitorsAction()
    {
        $startDate = new DateTime();
        $startDate->setTime(0, 0, 0)->sub(new DateInterval('P7D'));

        // Get turnovers         /** @var array $fetchAmount */
        $fetchAmount = $this->get('db')->fetchRow(
            'SELECT ( SELECT sum(invoice_amount/currencyFactor) AS amount FROM s_order WHERE TO_DAYS(ordertime) = TO_DAYS(now()) AND status != 4 AND status != -1 ) AS today, ( SELECT sum(invoice_amount/currencyFactor) AS amount FROM s_order WHERE TO_DAYS(ordertime) = (TO_DAYS( NOW( ) )-1) AND status != 4 AND status != -1 ) AS yesterday '
switch ($condition->getDirection()) {
            case ReleaseDateCondition::DIRECTION_FUTURE:
                $date->add($interval);

                $query->andWhere('variant.releasedate <= ' . $min);
                $query->andWhere('variant.releasedate > ' . $now);
                $query->setParameter($min$date->format('Y-m-d'));
                $query->setParameter($now$dateNow->format('Y-m-d'));
                break;

            case ReleaseDateCondition::DIRECTION_PAST:
                $date->sub($interval);

                $query->andWhere('variant.releasedate >= ' . $max);
                $query->andWhere('variant.releasedate <= ' . $now);
                $query->setParameter($max$date->format('Y-m-d'));
                $query->setParameter($now$dateNow->format('Y-m-d'));
                break;
        }
    }
}


    public function checkHash(string $hash, Context $context): bool
    {
        $criteria = new Criteria();
        $criteria->addFilter(
            new EqualsFilter('hash', $hash)
        );

        $recovery = $this->getUserRecovery($criteria$context);

        $validDateTime = (new \DateTime())->sub(new \DateInterval('PT2H'));

        return $recovery && $validDateTime < $recovery->getCreatedAt();
    }

    public function updatePassword(string $hash, string $password, Context $context): bool
    {
        if (!$this->checkHash($hash$context)) {
            return false;
        }

        $criteria = new Criteria();
        


    private function checkHash(string $hash, Context $context): bool
    {
        $criteria = new Criteria();
        $criteria->addFilter(
            new EqualsFilter('hash', $hash)
        );

        $recovery = $this->customerRecoveryRepository->search($criteria$context)->first();

        $validDateTime = (new \DateTime())->sub(new \DateInterval('PT2H'));

        return $recovery && $validDateTime < $recovery->getCreatedAt();
    }
}
public static function validContentProvider()
    {
        return [
            'obj' => [new StringableObject()],
            'string' => ['Foo'],
            'int' => [2],
        ];
    }

    protected function createDateTimeOneHourAgo()
    {
        return $this->createDateTimeNow()->sub(new \DateInterval('PT1H'));
    }

    protected function createDateTimeOneHourLater()
    {
        return $this->createDateTimeNow()->add(new \DateInterval('PT1H'));
    }

    protected function createDateTimeNow()
    {
        $date = new \DateTime();

        
$this->forward('index');

            return;
        }

        $toDate = $this->Request()->get('toDate');
        $fromDate = $this->Request()->get('fromDate');

        // If a "fromDate" is passed, format it over the \DateTime object. Otherwise, create a new date with today         if (empty($fromDate) || !Zend_Date::isDate($fromDate, 'Y-m-d')) {
            $fromDate = new DateTime();
            $fromDate = $fromDate->sub(new DateInterval('P1M'));
        } else {
            $fromDate = new DateTime($fromDate);
        }

        // If a "toDate" is passed, format it over the \DateTime object. Otherwise, create a new date with today         if (empty($toDate) || !Zend_Date::isDate($toDate, 'Y-m-d')) {
            $toDate = new DateTime();
        } else {
            $toDate = new DateTime($toDate);
        }

        
 {
        $search->addPostFilter(
            $this->getQuery($criteriaPart)
        );
    }

    private function getQuery(CreateDateCondition $criteriaPart): RangeQuery
    {
        $date = new DateTime();
        $intervalSpec = 'P' . $criteriaPart->getDays() . 'D';
        $interval = new DateInterval($intervalSpec);
        $date->sub($interval);

        return new RangeQuery('formattedCreatedAt', [
            'gte' => $date->format('Y-m-d'),
        ]);
    }
}


    /** * Returns a new Time instance with $seconds subtracted from the time. * * @return static */
    public function subSeconds(int $seconds)
    {
        $time = clone $this;

        return $time->sub(DateInterval::createFromDateString("{$seconds} seconds"));
    }

    /** * Returns a new Time instance with $minutes subtracted from the time. * * @return static */
    public function subMinutes(int $minutes)
    {
        $time = clone $this;

        
public function testIsNotNewCustomer(): void
    {
        Feature::skipTestIfActive('v6.6.0.0', $this);

        $rule = new IsNewCustomerRule();

        $cart = new Cart('test');

        $customer = new CustomerEntity();
        $customer->setFirstLogin(
            (new \DateTime())->sub(
                new \DateInterval('P' . 10 . 'D')
            )
        );

        $context = $this->createMock(SalesChannelContext::class);

        $context
            ->method('getCustomer')
            ->willReturn($customer);

        static::assertFalse(
            

    public static function getSubscribedEvents()
    {
        return [
            'Shopware_CronJob_CleanupSignatures' => 'cleanup',
        ];
    }

    public function cleanup()
    {
        $date = (new DateTime())
            ->sub(new DateInterval('P10D'))
            ->format('Y-m-d');

        $this->connection->executeUpdate(
            'DELETE FROM ' . BasketPersister::DBAL_TABLE . ' WHERE created_at < :createdAt',
            [':createdAt' => $date]
        );

        return true;
    }
}
Home | Imprint | This part of the site doesn't use cookies.