createFromDateString example

static::assertSame('P0Y0M1DT0H0M0S', (string) $dateInterval);
    }

    public function testCreateFromStringWithInvalidValue(): void
    {
        $dateInterval = DateInterval::createFromString('this does not belong here');
        static::assertNull($dateInterval);
    }

    public function testCreateFromDateString(): void
    {
        $dateInterval = DateInterval::createFromDateString('P1D');
        static::assertInstanceOf(DateInterval::class$dateInterval);
        static::assertSame('P0Y0M1DT0H0M0S', (string) $dateInterval);
    }

    public function testCreateFromDateStringWithInvalidValue(): void
    {
        $dateInterval = DateInterval::createFromDateString('this does not belong here');
        static::assertFalse($dateInterval);
    }

    public function testCreateFromDateInterval(): void
    {
if ($count > $current['limit'] && $next && $count <= $next['limit']) {
                return $current;
            }
        }

        return null;
    }

    private function intervalToSeconds(string $interval): int
    {
        return TimeUtil::dateIntervalToSeconds(\DateInterval::createFromDateString($interval));
    }
}
    // --------------------------------------------------------------------
    /** * Returns a new Time instance with $seconds added to the time. * * @return static */
    public function addSeconds(int $seconds)
    {
        $time = clone $this;

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

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

        
$limiter = $this->createLimiter();
        $rateLimit = $limiter->consume();
        $this->assertTrue($rateLimit->isAccepted());
        $this->assertEquals(9, $rateLimit->getRemainingTokens());
    }

    public function testBucketResilientToTimeShifting()
    {
        $serverOneClock = microtime(true) - 1;
        $serverTwoClock = microtime(true) + 1;

        $bucket = new TokenBucket('id', 100, new Rate(\DateInterval::createFromDateString('5 minutes'), 10)$serverTwoClock);
        $this->assertSame(100, $bucket->getAvailableTokens($serverTwoClock));
        $this->assertSame(100, $bucket->getAvailableTokens($serverOneClock));

        $bucket = new TokenBucket('id', 100, new Rate(\DateInterval::createFromDateString('5 minutes'), 10)$serverOneClock);
        $this->assertSame(100, $bucket->getAvailableTokens($serverTwoClock));
        $this->assertSame(100, $bucket->getAvailableTokens($serverOneClock));
    }

    public function testPeekConsume()
    {
        $limiter = $this->createLimiter();

        
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Stamp\DelayStamp;

/** * @author Yanick Witschi <yanick.witschi@terminal42.ch> */
class DelayStampTest extends TestCase
{
    public function testDelayFor()
    {
        $stamp = DelayStamp::delayFor(\DateInterval::createFromDateString('30 seconds'));
        $this->assertSame(30000, $stamp->getDelay());
        $stamp = DelayStamp::delayFor(\DateInterval::createFromDateString('30 minutes'));
        $this->assertSame(1800000, $stamp->getDelay());
        $stamp = DelayStamp::delayFor(\DateInterval::createFromDateString('30 hours'));
        $this->assertSame(108000000, $stamp->getDelay());

        $stamp = DelayStamp::delayFor(\DateInterval::createFromDateString('-5 seconds'));
        $this->assertSame(-5000, $stamp->getDelay());
    }

    public function testDelayUntil()
    {
try {
            if (\is_string($interval) && 'P' === ($interval[0] ?? '')) {
                $this->intervalInSeconds = $this->calcInterval(new \DateInterval($interval));
                $this->description = sprintf('every %d seconds (%s)', $this->intervalInSeconds, $interval);

                return;
            }

            $i = $interval;
            if (\is_string($interval)) {
                $this->description = sprintf('every %s', $interval);
                $i = \DateInterval::createFromDateString($interval);
            } else {
                $a = (array) $interval;
                $this->description = \PHP_VERSION_ID >= 80200 && $a['from_string'] ? $a['date_string'] : 'DateInterval';
            }

            if ($this->canBeConvertedToSeconds($i)) {
                $this->intervalInSeconds = $this->calcInterval($i);
                if ('DateInterval' === $this->description) {
                    $this->description = sprintf('every %s seconds', $this->intervalInSeconds);
                }
            } else {
                
yield ['every 20 seconds', new PeriodicalTrigger(20, $from$until)];
        yield ['every 20 seconds', new PeriodicalTrigger('20', $from$until)];
        yield ['every 2 seconds (PT2S)', new PeriodicalTrigger('PT2S', $from$until)];
        yield ['every 20 seconds', new PeriodicalTrigger('20 seconds', $from$until)];
        yield ['every 4 minutes 20 seconds', new PeriodicalTrigger('4 minutes 20 seconds', $from$until)];
        yield ['every 2 hours', new PeriodicalTrigger('2 hours', $from$until)];
        yield ['every 2 seconds', new PeriodicalTrigger(new \DateInterval('PT2S')$from$until)];
        yield ['DateInterval', new PeriodicalTrigger(new \DateInterval('P1D')$from$until)];

        if (\PHP_VERSION_ID >= 80200) {
            yield ['last day of next month', new PeriodicalTrigger(\DateInterval::createFromDateString('last day of next month')$from$until)];
        }
    }

    /** * @dataProvider providerGetNextRunDates */
    public function testGetNextRunDates(\DateTimeImmutable $from, TriggerInterface $trigger, array $expected, int $count = 0)
    {
        $this->assertEquals($expected$this->getNextRunDates($from$trigger$count ?? \count($expected)));
    }

    


        $emailRecipientIds = array_map(fn ($id) => ['id' => $id]$emailRecipient->getIds());

        $this->newsletterRecipientRepository->delete($emailRecipientIds, Context::createDefaultContext());
    }

    private function getExpiredNewsletterRecipientCriteria(): Criteria
    {
        $criteria = new Criteria();

        $dateTime = (new \DateTime())->add(\DateInterval::createFromDateString('-30 days'));

        $criteria->addFilter(new RangeFilter(
            'createdAt',
            [
                RangeFilter::LTE => $dateTime->format(\DATE_ATOM),
            ]
        ));

        $criteria->addFilter(new EqualsFilter('status', 'notSet'));

        $criteria->setLimit(999);

        
Home | Imprint | This part of the site doesn't use cookies.