Create a Verta instance from a DateTime one

@param string $format
@param string $datetime [optional]
@param bool $timezone [optional]
@return static
763497
public static function parseFormat($format,$datetime, $timezone = null) {
        $datetime = str_replace(self::$monthYear, range(1,12), $datetime);

        $parse = date_parse_from_format($format, $datetime);
        if($parse['error_count'] == 0 && self::isValideDate($parse['year'], $parse['month'], $parse['day']) && self::isValideTime($parse['hour'], $parse['minute'], $parse['second'])){
            list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
            list($hour,$minute, $second) = array($parse['hour'], $parse['minute'], $parse['second']);

            $timezone = self::createTimeZone($timezone);
            $datetime = new DateTime(sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $timezone);
            return new static($datetime);
        }
        else{
            throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
        }
    }
417520
static function Parse($format, $dateTimeString)
     {
         $dt = \DateTime::createFromFormat($format, $dateTimeString);
         if (!$dt)
             return null;
         
         return self::FromDateTime($dt);
     }
1177636
public static function formatTimestamp($timestamp, $format = self::DEFAULT_TIME_FORMAT, $timezone = self::DEFAULT_TIMEZONE)
    {
        $dateTime = new DateTime();
        $dateTime->setTimestamp($timestamp);
        $dateTime->setTimezone(new DateTimeZone($timezone));
        return $dateTime->format($format);
    }
323206
public static function createFromTimestamp(?int $timestamp = null, ?string $timeZone = null): DateTimeInterface
    {
        $dateTimeZone = is_string($timeZone) ? new DateTimeZone($timeZone) : null;
        $timestamp = is_int($timestamp) ? $timestamp : time();

        $dateTime = new DateTimeImmutable('now', $dateTimeZone);

        return $dateTime->setTimestamp($timestamp);
    }
532052
public static function createFromFormat($format, $time, $timezone = null)
    {
        if (null === $timezone) {
            $timezone = self::getServerTimezone();
        }

        if (null === $timezone) {
            // This is necessary due to how native DateTime handles passing null for a timezone (it doesnt)
            $parent = parent::createFromFormat($format, $time);
        } else {
            $parent = parent::createFromFormat($format, $time, $timezone);
        }

        if (empty($parent)) {
            throw new TypeException('Could not create DateTime from the given format');
        }

        $datetime = new self('@' . $parent->getTimestamp());
        if (null !== $timezone) {
            $datetime->setTimezone($timezone);
        }

        return $datetime;
    }
113278
public static function createFromFormat($format, $time, $object = null)
    {
        if ($object !== null) {
            $dt = parent::createFromFormat($format, $time, $object);
        } else {
            $dt = parent::createFromFormat($format, $time);
        }

        $lastErrors = parent::getLastErrors();

        if ($dt instanceof \DateTimeInterface) {
            return new static($dt->format('Y-m-d H:i:s.u'), $dt->getTimezone());
        }

        throw new \InvalidArgumentException(implode(PHP_EOL, $lastErrors['errors']));
    }
417958
public function dateTimeRange(string $format = DateTime::DISPLAY_FORMAT) : FieldBuilderBase
    {
        return $this->field->type(new DateTimeRangeType($format));
    }
1123756
public static function parse($format, $time, DateTimeZone $timezone =  NULL) {
    if (!isset($timezone) && date_default_timezone_get() != '') {
      $timezone = new DateTimeZone(date_default_timezone_get());
    }

    $ret = parent::createFromFormat($format, $time, $timezone);
    
    if ($ret === FALSE) {
      throw new ParsingException('Aus '.Code::varInfo($time).' konnte keinen Zeitinformationen des Formates: '.Code::varInfo($format).' geparst werden. lastErrors: '.print_r(DateTime::getLastErrors(),true));
    }
    
    return new static($ret);
  }
794336
public static function createDateFromTimestamp($timestamp, DateTimeZone $dateTimeZone = NULL) {
    $openYLocaleDate = new OpenYLocaleDate();
    $openYLocaleDate->setDateFromTimeStamp($timestamp, $dateTimeZone);
    return $openYLocaleDate;
  }
55481
public static function createFromFormat($formatOrTime, $time = '', $timezone = null)
	{
		if ( $time === '' ) {
			$parsed = date_parse($formatOrTime);
		} else {
			$parsed = date_parse_from_format($formatOrTime, $time);
		}

		$d = new self();

		if ( $timezone !== null ) {
			$d->setTimezone( $timezone );
		}

		$d->setDate($parsed);
		$d->setTime($parsed);

		return $d;
	}
528857
public function formatDateTime(\DateTime $datetime, $format, $calendar = \IntlDateFormatter::GREGORIAN)
    {
        $types = array(
            \IntlDateFormatter::NONE,
            \IntlDateFormatter::NONE,
        );
        if (is_array($format)) {
            if (isset($format[0])) {
                $types[0] = $format[0];
            }
            if (isset($format[1])) {
                $types[1] = $format[1];
            }
            $pattern = null;
        } else {
            $pattern = $format;
        }
        $formatter = new \IntlDateFormatter(
            $this->currentLocale,
            $types[0],
            $types[1],
            $datetime->getTimezone()->getName(),
            $calendar,
            $pattern
        );
        return $formatter->format($datetime);
    }
638358
public static function createFromFormat( $format, $time, $timezone = null ) {

		/** @var \DateTimeInterface $created */
		$created = empty( $timezone ) ?
			parent::createFromFormat( $format, $time ) :
			parent::createFromFormat( $format, $time, $timezone );

		if ( false === $created ) {
			return false;
		}

		$wp_date_time = new static( '@' . $created->getTimestamp() );

		return $wp_date_time->setTimezone( $created->getTimezone() );
	}
82013
public function withTimeZone(\DateTimeZone $timezone) : self
    {
        if ($this->timezone()->getName() === $timezone->getName()) {
            return $this;
        }

        $instance = clone $this;

        $instance->date->setTimezone($timezone);

        return $instance;
    }
47769
protected function dateFormatter($dateTime, $format)
    {
        if (is_numeric($dateTime)) {
            return gmdate($format, (int) $dateTime);
        }

        if (is_string($dateTime)) {
            $dateTime = new \DateTime($dateTime);
        }

        if ($dateTime instanceof \DateTimeInterface) {
            static $utc;
            if (!$utc) {
                $utc = new \DateTimeZone('UTC');
            }
            return $dateTime->setTimezone($utc)->format($format);
        }

        throw new \InvalidArgumentException('Date/Time values must be either '
            . 'be a string, integer, or DateTime object');
    }
493777
public function formatDate(\DateTime $datetime, $format, $useOffset = null)
    {
        if (is_null($useOffset)) {
            $useOffset = $this->getParameter('nyroDev_utility.dateFormatUseOffsetDefault');
        }

        $offset = 0;
        if ($useOffset) {
            $tz = new \DateTimeZone(date_default_timezone_get());
            $offset = -1 * $tz->getOffset($datetime) + $datetime->getOffset();
        }

        return strftime($this->trans($format), $datetime->getTimestamp() + $offset);
    }
185904
public static function fromTimestamp($timestamp, DateTimeZone $dateTimeZone = null)
    {
        $base = new GregorianDateTime(
            date('Y-m-d H:i:s', $timestamp),
            self::checkForDateTimeZone($dateTimeZone)
        );

        return new DateTime($base);
    }
836010
public function tzFormat($format, $tz = null)
    {
        if (isset($tz)) {
            $this->setTimezone(new DateTimeZone($tz));
        }

        return $this->format($format);
    }