Creates a LocalTime from a native DateTime or DateTimeImmutable object.

@param \DateTimeInterface $dateTime

@return LocalTime
761468
public static function fromDateTime(\DateTimeInterface $dateTime) : LocalTime
    {
        return new LocalTime(
            (int) $dateTime->format('G'),
            (int) $dateTime->format('i'),
            (int) $dateTime->format('s'),
            1000 * (int) $dateTime->format('u')
        );
    }
215073
public static function now(?string $timezone = null): DateTime
    {
        $timezone = $timezone ?: date_default_timezone_get();
        assert(Validate::isTimezone($timezone), sprintf('Invalid timezone: %s', $timezone));

        $dateTime = new DateTimeImmutable('now', new DateTimeZone($timezone));
        $year = (int) $dateTime->format('Y');
        $month = (int) $dateTime->format('n');
        $day = (int) $dateTime->format('j');
        $hour = (int) $dateTime->format('G');
        $minute = (int) $dateTime->format('i');
        $second = (int) $dateTime->format('s');

        return new static(
            Date::create($year, $month, $day),
            Time::create($hour, $minute, $second),
            Timezone::create($timezone)
        );
    }
442564
private static function validateDateTime($datetime)
	    {
	        if ($datetime instanceof DateTimeInterface || $datetime instanceof DateTime) {
	            return $datetime;
	        }

	        return new DateTime((string) $datetime);
	    }
293023
public function withDateTime(\DateTimeImmutable $dt): self
    {
        $obj = clone $this;
        $obj->_dateTime = $dt;
        return $obj;
    }
85189
public static function createFromDateTime(DateTimeInterface $dateTime)
    {
        return static::create(Date::createFromDateTime($dateTime), TimeOfDay::createFromDateTime($dateTime));
    }
278511
public static function from(DateTimeParseResult $result) : LocalDateTime
    {
        return new LocalDateTime(
            LocalDate::from($result),
            LocalTime::from($result)
        );
    }
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);
        }
    }
925128
public function withSecond(int $second) : LocalDateTime
    {
        $time = $this->time->withSecond($second);

        if ($time === $this->time) {
            return $this;
        }

        return new LocalDateTime($this->date, $time);
    }
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())
        );
    }
539065
public function setDateTime(\DateTimeInterface $dateTime)
    {
        if ($dateTime instanceof \DateTime) {
            $immutable = new \DateTimeImmutable('@'.$dateTime->getTimestamp());
            $dateTime = $immutable->setTimezone($dateTime->getTimezone());
        }
        $this->dateTime = $dateTime;
    }
725798
public static function fromNative(\DateTimeInterface $dateTime) : Date
    {
        return new self((int)$dateTime->format('Y'), (int)$dateTime->format('m'), (int)$dateTime->format('d'));
    }
494405
public static function fromNative(DateTimeInterface $dateTime): Date
    {
        $year = (int) $dateTime->format('Y');
        $month = (int) $dateTime->format('n');
        $day = (int) $dateTime->format('j');

        return new static($year, $month, $day);
    }
8152
public static function fromNative(\DateTimeInterface $dateTime) : TimeOfDay
    {
        return new self((int)$dateTime->format('H'), (int)$dateTime->format('i'), (int)$dateTime->format('s'));
    }
1306172
public static function fromNativeDateTime(\DateTime $date_time)
    {
        $date = Date::fromNativeDateTime($date_time);
        $time = Time::fromNativeDateTime($date_time);

        return new static($date, $time);
    }
1034630
static function dateTimeImmutable(?\DateTimeZone $timezone = null): \DateTimeImmutable
    {
        if (self::$now !== null) {
            $now = \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', self::$now));
            $now = $now->setTimezone($timezone ?? new \DateTimeZone(date_default_timezone_get()));

            return $now;
        }

        return new \DateTimeImmutable('now', $timezone);
    }
402253
public function setEmbargoTime(DateTime $time): PageInterface
    {
        $this->addVersion([
            PageVersion::ATTR_PENDING_APPROVAL => false,
            PageVersion::ATTR_EMBARGOED_UNTIL  => $time->getTimestamp(),
        ]);

        return $this;
    }
1105708
public static function fromDateTime(\DateTimeInterface $dateTime) : LocalDate
    {
        return new LocalDate(
            (int) $dateTime->format('Y'),
            (int) $dateTime->format('n'),
            (int) $dateTime->format('j')
        );
    }