/** * Create a copy of a DateTime instance. A new instance will be created if a PHPDateTime instance was given, or if * the time was specified as a string. * * @param DateTime|PHPDateTime|string|null $other The DateTime instance. Or a PHPDateTime instance, the time as a * string or null. * * @return DateInterval|null The new DateTime instance, or null on failure. * * @throws InvalidDateTimeException Throws InvalidDateTimeException if the date time instance is invalid. */ public static function instance($other) { // Reconstruct the object if it's a DateTime instance if ($other instanceof self) { return new static($other->format(self::DEFAULT_FORMAT_COMPLETE), $other->getTimeZone()); } // Parse and return the other instance if (($instance = static::parse($other)) === null) { throw new InvalidDateTimeException('The given date time instance is invalid'); } return $instance; }