Creates a time object from the time part of the supplied date time.

@param \DateTimeInterface $dateTime

@return TimeOfDay
8152
public static function fromNative(\DateTimeInterface $dateTime) : TimeOfDay
    {
        return new self((int)$dateTime->format('H'), (int)$dateTime->format('i'), (int)$dateTime->format('s'));
    }
1109558
public static function from($time): self
	{
		if ($time instanceof DateTimeInterface) {
			return new static($time->format('Y-m-d H:i:s'), $time->getTimezone());

		} elseif (is_numeric($time)) {
			return (new static('@' . $time))
				->setTimezone(new DateTimeZone(date_default_timezone_get()));

		} else {
			return new static($time);
		}
	}
2621
public function withExpiry(\DateTimeInterface $date): self
    {
        $new = clone $this;

        if ($date instanceof \DateTimeImmutable) {
            $new->expiry = $date;
        } elseif ($date instanceof \DateTime) {
            $new->expiry = \DateTimeImmutable::createFromMutable($date);
        } else {
            $new->expiry = new \DateTimeImmutable("@" . $date->getTimestamp());
        }

        return $new;
    }
1033557
public static function buildFromDateTimeInterface(DateTimeInterface $date)
    {
        $parts = explode('|', $date->format('Z|I|T'));

        return new static((int)$parts[0], (bool)$parts[1], $parts[2]);
    }
1205368
protected function getDateTime($dateTime)
    {
        if ($dateTime instanceof \DateTime) {
            return $dateTime;
        }

        if ((is_string($dateTime) && (int) $dateTime > 0) || is_numeric($dateTime)) {
            return (new \DateTime())->setTimestamp($dateTime);

        }

        throw new \common_Exception(__('A date has to be a Datetime or timestamp'));
    }
682656
public static function FromDateTime( \DateTime $dt ) : DateTime
   {

      if ( $dt instanceof DateTime )
      {
         return clone $dt;
      }

      return new DateTime( $dt->format('Y-m-d H:i:s.u'), $dt->getTimezone() );

   }
136950
public static function fromDateTime(DateTime $dateTime)
    {
        $dateTime = clone $dateTime;

        return new static($dateTime->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp());
    }
539065
public function setDateTime(\DateTimeInterface $dateTime)
    {
        if ($dateTime instanceof \DateTime) {
            $immutable = new \DateTimeImmutable('@'.$dateTime->getTimestamp());
            $dateTime = $immutable->setTimezone($dateTime->getTimezone());
        }
        $this->dateTime = $dateTime;
    }
291822
public static function convertToDbDate(\DateTime $dateTime) {
		
		$currentTz = $dateTime->getTimezone();
		$dateTime->setTimezone(new \DateTimeZone(BASE_TIMEZONE));
		$ret = $dateTime->format('Y-m-d');
		$dateTime->setTimezone($currentTz);
		return $ret;
		
	}
607869
protected function getDateTimeForDb(DateTimeInterface $dateTime): string
    {
        try {
            return Type::getType(Type::DATETIME)
                ->convertToDatabaseValue($dateTime, $this->getConnection()->getDatabasePlatform());
        } catch (DBALException $exception) {
            $message = 'DateTime conversion to database format failed.';
            throw new RepositoryException($message, 0, $exception);
        }
    }
424675
public function setDate(DateTimeInterface $dateTime)
    {
        if (!$this->setHeaderFieldModel('Date', $dateTime)) {
            $this->getHeaders()->addDateHeader('Date', $dateTime);
        }

        return $this;
    }
305291
public function setDateTime(DateTimeInterface $dt)
    {
        $tz = $dt->getTimeZone();
        $isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z']);

        if ($isUtc) {
            $value = $dt->format('Ymd\\THis\\Z');
        } else {
            // Calculating the offset.
            $value = $dt->format('Ymd\\THisO');
        }

        $this->value = $value;
    }
982004
public function toLocalTime(\DateTime $dateTime = null)
    {
        if ($dateTime === null) {
            $dateTime = new \DateTime();
        }

        return $dateTime->setTimezone($this->getTimeZone());
    }
691370
public static function createDateFromDateTime(DateTime $dateTime, DateTimeZone $dateTimeZone = NULL) {
    $openYLocaleDate = new OpenYLocaleDate();
    $openYLocaleDate->setDateFromDateTime($dateTime, $dateTimeZone);
    return $openYLocaleDate;
  }
1222049
public static function formatDate(\DateTimeInterface $dateTime, $format)
    {
        $phpFormats = array(
            self::DATE => "Y-m-d",
            self::DATE_AND_TIME => 'Y-m-d\TH:i:s\Z',
        );
        $phpFormat = $phpFormats[$format];

        return $dateTime->format($phpFormat);
    }
137108
public function toNative(): DateTimeInterface
    {
        $time = sprintf(
            '%04d-%02d-%02dT%02d:%02d:%02d',
            $this->year(),
            $this->month(),
            $this->day(),
            $this->hour(),
            $this->minute(),
            $this->second()
        );

        return NativeDateTime::createFromFormat(
            static::STRING_FORMAT,
            $time,
            new DateTimeZone($this->timezone->toString())
        );
    }
53936
public static function fromDateTime(DateTime $dateTime)
    {
        $date = new Date();
        $date->setYear(intval($dateTime->format('Y')));
        $date->setMonth(intval($dateTime->format('m')));
        $date->setDay(intval($dateTime->format('d')));

        $result = new AdManagerDateTime();
        $result->setDate($date);
        $result->setHour(intval($dateTime->format('H')));
        $result->setMinute(intval($dateTime->format('i')));
        $result->setSecond(intval($dateTime->format('s')));
        $result->setTimeZoneID($dateTime->format('e'));

        return $result;
    }