@param string        $time
@param \DateTimeZone $timeZone

@return \DateTimeImmutable
484435
public static function newImmutablePhpDateTime($time = 'now', \DateTimeZone $timeZone = null)
    {
        if (self::DATETIME_SYSTEM === self::$type) {
            return new \DateTimeImmutable($time, $timeZone);
        }

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

        $date = self::getFixedImmutableTimeFromConfiguredTimestamp($time, $timeZone);
        $timePassedSinceInstantiation = abs(
            (new \DateTime())->getTimestamp() - self::$offsetTimestamp
        );

        return $date->modify("+{$timePassedSinceInstantiation} seconds");
    }
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;
    }
734663
public static function createFromDefaultFormat($datetime, $timezone = null)
    {
        return self::createFromFormat(self::$defaultFormat, $datetime, $timezone);
    }
764533
public static function diff(DateTime $time,DateTime $time0=null)
    {
        if($time0==null){
            $time0=new DateTime();
        }
        return $time->diffFrom($time0);
    }
1337266
public function setTimezone($timezone) {
		if (!is_a($timezone, 'DateTimeZone')) $timezone = new \DateTimeZone($timezone);
		parent::setTimezone($timezone);
		return $this;
	}
1166756
public function setEndTimezone($timezone = 'UTC')
	{
		$this->end->setTimezone(is_string($timezone) ? new \DateTimeZone($timezone) : $timezone);
		return $this;
	}
745840
public function toDateTime(DateTimeZone $timeZone = null): DateTime
    {
        $date = \DateTime::createFromFormat('U.u', $this->sec . '.' . $this->uSec);
        if ($timeZone) {
            $date->setTimezone($timeZone);
        }

        return $date;
    }
268462
public static function fromString(string $time, string $tz = null): self
    {
        try {
            if (!isset($tz)) {
                $tz = date_default_timezone_get();
            }
            return new static(
                new \DateTimeImmutable($time, self::_createTimeZone($tz)));
        } catch (\Exception $e) {
            throw new \RuntimeException(
                "Failed to create DateTime: " .
                self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
        }
    }
1020001
protected function expressionPasses(\DateTimeZone $timeZone)
    {
        $now = $this->getClock()
            ->now();
        $now = $now->setTimezone($timeZone);

        if ($this->timezone) {
            $taskTimeZone = \is_object($this->timezone) && $this->timezone instanceof \DateTimeZone
                ? $this->timezone
                    ->getName()
                : $this->timezone
            ;

            $now = $now->setTimezone(
                new \DateTimeZone(
                    $taskTimeZone
                )
            );
        }

        return CronExpression::factory($this->expression)->isDue($now->format('Y-m-d H:i:s'));
    }
274224
final protected function _getTimeZone($timezone = null)
	{
		if ($timezone = strtoupper($timezone) and defined("\\DateTimeZone::{$timezone}")) {
			$timezone = new \DateTimeZone($timezone);
		} elseif (! ($timezone instanceof \DateTimeZone)) {
			@date_default_timezone_set(date_default_timezone_get());
			$timezone = new \DateTimeZone(date_default_timezone_get());
		}
		return $timezone;
	}
900726
public static function fromString($time)
    {
        try {
            $date = new \DateTime($time);
        } catch (\Exception $e) {
            throw new \InvalidArgumentException(sprintf('Invalid time "%s".', $time));
        }

        return self::fromDate($date);
    }
202823
public function withTime(LocalTime $time) : LocalDateTime
    {
        if ($time->isEqualTo($this->time)) {
            return $this;
        }

        return new LocalDateTime($this->date, $time);
    }
38906
public static function now(?string $timezone = null): Time
    {
        $timezone = $timezone ?: date_default_timezone_get();
        assert(Validate::isTimezone($timezone), sprintf('Invalid timezone: %s', $timezone));

        $dateTime = new DateTimeImmutable('now', new DateTimeZone($timezone));
        $hour = (int) $dateTime->format('G');
        $minute = (int) $dateTime->format('i');
        $second = (int) $dateTime->format('s');

        return new static($hour, $minute, $second);
    }
1058484
public function setTime(DateTime $time = null)
    {
        $timestamp = $time ? $time->getTimestamp() : null;

        $this->session->put($this->timePersistenceKey, $timestamp);

        if ($time) {
            $this->setState(static::HISTORY);
        }

        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;
    }
63171
public static function parse($datetime, $timezone = null) {
        $monthName = array_map(function ($value) {
            return ' ' . $value . ' ';
        }, self::$monthYear);
        $monthValue = array_map(function ($value) {
            return '-' . $value . '-';
        }, range(1,12));
        $datetime = str_replace($monthName, $monthValue, $datetime);

        $parse = date_parse($datetime);
        if($parse['error_count'] == 0){
            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));
        }
    }
1229941
public function setDateByTimezone($timezone) {
    if (is_string($timezone)) {
      $timezone = new DateTimeZone($timezone);
    }
    $this->convertedTimezone = $timezone;
    $new_date_utc = $this->date->getTimeStamp() - $timezone->getOffset($this->date);
    $new_date = new DateTime();
    $new_date->setTimestamp($new_date_utc);
    $this->date = $new_date;
  }