Creates a ZonedDateTime from a native DateTime or DateTimeImmutable object.

@param \DateTimeInterface $dateTime

@return ZonedDateTime

@throws DateTimeException If the DateTime object has no timezone.
195930
public static function fromDateTime(\DateTimeInterface $dateTime) : ZonedDateTime
    {
        $localDateTime = LocalDateTime::fromDateTime($dateTime);

        $dateTimeZone = $dateTime->getTimezone();

        if ($dateTimeZone === false) {
            throw new DateTimeException('This DateTime object has no timezone.');
        }

        $timeZone = TimeZone::fromDateTimeZone($dateTimeZone);

        if ($timeZone instanceof TimeZoneOffset) {
            $timeZoneOffset = $timeZone;
        } else {
            $timeZoneOffset = TimeZoneOffset::ofTotalSeconds($dateTime->getOffset());
        }

        $instant = Instant::of($dateTime->getTimestamp(), $localDateTime->getNano());

        return new ZonedDateTime($localDateTime, $timeZoneOffset, $timeZone, $instant);
    }
480422
public function getDatetimeObject($datetime = null)
    {
        if ($datetime instanceof DateTimeInterface) {
            return $datetime;
        }

        if (is_integer($datetime)) {
            $datetime = date('Y-m-d H:i:s', $datetime);
        }

        return new 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'));
    }
922429
protected function dateTime(): DateTimeImmutable
    {
        if ($this->dateTime === null) {
            $year = $this->year();
            $month = $this->month();
            $day = $this->day();
            $hour = $this->hour();
            $minute = $this->minute();
            $second = $this->second();
            $timezone = $this->timezone()->toString();
            $this->dateTime = self::createNative($year, $month, $day, $hour, $minute, $second, $timezone);
        }

        return $this->dateTime;
    }
48947
public function toSqlTimeWithoutTimeZone(DateTimeInterface $time, Provider $provider = null) : string
    {
        $this->setParameterProvider($provider);

        return $time->format($provider->getTimeWithoutTimeZoneFormat());
    }
315026
protected function formatDateTime(DateTimeInterface $date): string
    {
        return (new DateTime)
            ->setTimestamp($date->getTimestamp())
            ->setTimezone(new DateTimeZone('UTC'))
            ->format('Y-m-d\TH:i:s\Z');
    }
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);
    }
136950
public static function fromDateTime(DateTime $dateTime)
    {
        $dateTime = clone $dateTime;

        return new static($dateTime->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp());
    }
297790
public function getDeletedAtDatetime(string $timezone = null): ?DateTime
    {
        if (!$this->isDeleted()) {
            return null;
        }

        return new DateTime($this->getDeletedAt(), new DateTimeZone($timezone ?? 'UTC'));
    }
442564
private static function validateDateTime($datetime)
	    {
	        if ($datetime instanceof DateTimeInterface || $datetime instanceof DateTime) {
	            return $datetime;
	        }

	        return new DateTime((string) $datetime);
	    }
298787
public static function getDateTime($datetime = null)
    {
        if ($datetime instanceof \DateTime) {
            return clone $datetime;
        }
        if ($datetime instanceof \DateTimeImmutable) {
            return new \DateTime($datetime->format(\DateTime::ATOM));
        }
        if (\is_string($datetime)) {
            if (\is_numeric($datetime)) {
                /*
                    check if datetime is an int of the the form YYYYMMDD or YYYYMMDDHHMMSS
                    Debug::_log('datetime', $datetime)
                */
                $isTs = !preg_match('/^(19|20)\d{2}(0[1-9]|1[0-2])[0-3][0-9](([01]\d|2[0-3])\d[0-5]\d[0-5]\d)?$/', $datetime);
                if ($isTs) {
                    $datetime = '@'.$datetime;
                }
            }
            Debug::_log('datetime', $datetime);
            return new \DateTime($datetime);
        }
        if (\is_int($datetime) || \is_float($datetime)) {
            $dateTime = new \DateTime();
            $dateTime->setTimestamp($datetime);
            return $dateTime;
        }
        return new \DateTime();
    }
424675
public function setDate(DateTimeInterface $dateTime)
    {
        if (!$this->setHeaderFieldModel('Date', $dateTime)) {
            $this->getHeaders()->addDateHeader('Date', $dateTime);
        }

        return $this;
    }
1104462
public function toDateTime(\DateTimeZone $timeZone = null): \DateTime
    {
        if (null === self::$utc) {
            self::$utc = new \DateTimeZone('UTC');
        }

        $date = \DateTime::createFromFormat('!Y-m-d', $this->getValue(), $timeZone ?: self::$utc);
        if (!$date instanceof \DateTime) {
            $date = \DateTime::createFromFormat('!Y-m-d', (new \DateTime())->format('Y-m-d'), $timeZone ?: self::$utc);
        }

        if ($date->getOffset() !== 0) {
            $date->setTimezone(self::$utc);
        }

        return $date;
    }
982004
public function toLocalTime(\DateTime $dateTime = null)
    {
        if ($dateTime === null) {
            $dateTime = new \DateTime();
        }

        return $dateTime->setTimezone($this->getTimeZone());
    }
1119756
public static function newPhpDateTime($time = 'now', \DateTimeZone $timeZone = null)
    {
        if (self::DATETIME_SYSTEM === self::$type) {
            return new \DateTime($time, $timeZone);
        }

        if (self::DATETIME_FIXED === self::$type) {
            return self::getFixedTimeFromConfiguredTimestamp($time, $timeZone);
        }

        $date = self::getFixedTimeFromConfiguredTimestamp($time, $timeZone);
        $timePassedSinceInstantiation = abs(
            (new \DateTime())->getTimestamp() - self::$offsetTimestamp
        );
        $date->modify("+{$timePassedSinceInstantiation} seconds");

        return $date;
    }
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;
		
	}
521961
private function getAdoptedDateTime(DateTimeInterface $dateTime): \DateTime
    {
        return (new \DateTime())
            ->setTimestamp($dateTime->getTimestamp())
            ->setTimezone(new DateTimeZone('Asia/Manila'));
    }