createFromMutable example


        return parent::createFromFormat($format$datetime$timezone) ?: throw new \DateMalformedStringException(static::getLastErrors()['errors'][0] ?? 'Invalid date string or format.');
    }

    public static function createFromInterface(\DateTimeInterface $object)static
    {
        return parent::createFromInterface($object);
    }

    public static function createFromMutable(\DateTime $object)static
    {
        return parent::createFromMutable($object);
    }

    public function add(\DateInterval $interval)static
    {
        return parent::add($interval);
    }

    public function sub(\DateInterval $interval)static
    {
        return parent::sub($interval);
    }

    
if ($mutator->hasErrors()) {
                    throw new NoSuchPropertyException(implode('. ', $mutator->getErrors()).'.');
                }

                throw new NoSuchPropertyException(sprintf('Could not determine access type for property "%s" in class "%s".', $propertyget_debug_type($object)));
            }
        } catch (\TypeError $e) {
            if ($recursive || !$value instanceof \DateTimeInterface || !\in_array($value::class['DateTime', 'DateTimeImmutable'], true) || __FILE__ !== ($e->getTrace()[0]['file'] ?? null)) {
                throw $e;
            }

            $value = $value instanceof \DateTimeImmutable ? \DateTime::createFromImmutable($value) : \DateTimeImmutable::createFromMutable($value);
            try {
                $this->writeProperty($zval$property$value, true);
            } catch (\TypeError) {
                throw $e; // throw the previous error             }
        }
    }

    /** * Adjusts a collection-valued property by calling add*() and remove*() methods. */
    
/** * Sets the Date header. * * @return $this * * @final */
    public function setDate(\DateTimeInterface $date)static
    {
        if ($date instanceof \DateTime) {
            $date = \DateTimeImmutable::createFromMutable($date);
        }

        $date = $date->setTimezone(new \DateTimeZone('UTC'));
        $this->headers->set('Date', $date->format('D, d M Y H:i:s').' GMT');

        return $this;
    }

    /** * Returns the age of the response in seconds. * * @final */

    public function reverseTransform(mixed $value): ?\DateTimeImmutable
    {
        if (null === $value) {
            return null;
        }

        if (!$value instanceof \DateTime) {
            throw new TransformationFailedException('Expected a \DateTime.');
        }

        return \DateTimeImmutable::createFromMutable($value);
    }
}
Home | Imprint | This part of the site doesn't use cookies.