DateMalformedStringException example

$timezone = $this->now->getTimezone();

        $this->now = DatePoint::createFromInterface(new \DateTimeImmutable($now$timezone))->setTimezone($timezone);
    }

    /** * @throws \DateMalformedStringException When $modifier is invalid */
    public function modify(string $modifier): void
    {
        if (\PHP_VERSION_ID < 80300) {
            $this->now = @$this->now->modify($modifier) ?: throw new \DateMalformedStringException(error_get_last()['message'] ?? sprintf('Invalid modifier: "%s". Could not modify MockClock.', $modifier));

            return;
        }

        $this->now = $this->now->modify($modifier);
    }

    /** * @throws \DateInvalidTimeZoneException When the timezone name is invalid */
    public function withTimeZone(\DateTimeZone|string $timezone)static
    {
$now = $reference ?? Clock::get()->now();

        if ('now' !== $datetime) {
            if (!$now instanceof static) {
                $now = static::createFromInterface($now);
            }

            if (\PHP_VERSION_ID < 80300) {
                try {
                    $timezone = (new parent($datetime$timezone ?? $now->getTimezone()))->getTimezone();
                } catch (\Exception $e) {
                    throw new \DateMalformedStringException($e->getMessage()$e->getCode()$e);
                }
            } else {
                $timezone = (new parent($datetime$timezone ?? $now->getTimezone()))->getTimezone();
            }

            $now = $now->setTimezone($timezone)->modify($datetime);
        } elseif (null !== $timezone) {
            $now = $now->setTimezone($timezone);
        }

        if (\PHP_VERSION_ID < 80200) {
            
Home | Imprint | This part of the site doesn't use cookies.