@param DateTimeZone|null $timezone

@return self
167788
public static function now(DateTimeZone $timezone = null) : self
    {
        // Ensure microsecond precision.
        
        list($microsecond, $second) = explode(' ', microtime());
        
        $microsecond *= 10 ** 6;
        $second *= 10 ** 6;
        $timestamp = $second + $microsecond;
        
        $instance = static::fromTimestampWithMicroseconds($timestamp);
        
        if ($timezone) {
            $instance->date->setTimezone($timezone);
        }
        
        return $instance;
    }
91232
protected function withTimezone($timezone, $callback)
    {
        $currentTimezone = date_default_timezone_get();
        try {
            if ($timezone) {
                date_default_timezone_set($timezone);
            }
            return $callback();
        } finally {
            // Restore timezone
            if ($timezone) {
                date_default_timezone_set($currentTimezone);
            }
        }
    }
612428
public function setDateFromDateTime(DateTime $date = NULL, DateTimeZone $dateTimeZone = NULL) {
    $dateTimeZone = !empty($dateTimeZone) ? $dateTimeZone : new DateTimeZone('UTC');
    $this->date = !empty($date) ? $date : new DateTime($date);
    $this->date->setTimezone($dateTimeZone);
  }
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);
    }
939306
public static function createFromFormat($format, $datetime, $timezone = null)
    {
        $datepoint = parent::createFromFormat($format, $datetime, $timezone);
        if (false !== $datepoint) {
            return self::create($datepoint);
        }

        return $datepoint;
    }
1368710
public static function defaultTimezone($timezone = null)
	{
		if ($timezone !== null)
		{
			if ( ! $timezone instanceOf DateTimeZone)
			{
				$timezone = new DateTimeZone($timezone);
			}

			static::$defaultTimezone = $timezone;
		}

		return static::$defaultTimezone;
	}
734663
public static function createFromDefaultFormat($datetime, $timezone = null)
    {
        return self::createFromFormat(self::$defaultFormat, $datetime, $timezone);
    }
37664
private function createSession(string $timezone): bool {

		// checks if time zone name is valid
		if (!in_array($timezone, \DateTimeZone::listIdentifiers())) {
			$timezone = date_default_timezone_get();
		}
		
		// gets offset by timezone name
		$dt = new \DateTime('now', new \DateTimeZone($timezone));
		$diff = $dt->format('P');
		list ($hours, $mins) = explode(':', $diff);
		$offset = (float)$hours + ($hours > 0 ? ($mins / 60) : -($mins / 60));

		// creates session
		$session = new Session();

		$session->id				= session_id();
		$session->idUser			= $this->id;
		$session->startTime			= new \DateTime();
		$session->timezoneOffset	= $offset;
		$session->timezoneName		= $timezone;
		
		$res1 = $session->create();
		
		// updates last user login
		$this->lastLogin	= new \DateTime();
		$this->tzOffset		= $offset;
		$this->tzName		= $timezone;
		
		$res2 = $this->update('lastLogin');

		return ($res1 and $res2);
		
	}
1372663
public function dueEvents(\DateTimeZone $timeZone)
    {
        return \array_filter(
            $this->events,
            function (Event $event) use ($timeZone) {
                return $event->isDue($timeZone);
            }
        );
    }
1006660
public function getUpdated(\DateTimeZone $timezone = null): ?\DateTime
    {
        if (!is_null($timezone)) {
            $returnDate = clone $this->updated;
            $returnDate->setTimeZone($timezone);
            return $returnDate;
        }
        return $this->updated ?? null;
    }
1146736
protected function onTimeZone(?string $timeZoneCode)
    {
        if (\is_null($timeZoneCode)) {
            $this->timezone = null;
        } elseif (\in_array($timeZoneCode, \timezone_identifiers_list())) {
            $this->timezone = $timeZoneCode;
        }

        return $this;
    }
709830
public function datetime(string $format, \DateTimeZone $timeZone = null) : DateFieldBuilder
    {
        return $this->dateTypeBuilder(new DateTimeType($format, $timeZone));
    }
612459
public function withTimezone($timezone): DateTime
    {
        return new static(
            $this->date(),
            $this->time(),
            Timezone::create($timezone)
        );
    }
327625
public static function thisMonth($timeZone = null)
    {
        $now = null;
        $before = null;
        if ( is_null($timeZone) ) {
            $now = new \DateTime();
            $before = new \DateTime();
        } else {
            $now = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
            $before = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
        }
        $dayOfMonth = $now->format( "j" );
        $offset = $dayOfMonth - 1;
        $before->modify( "-$offset day" );
        $range = new Range( $before, $now );

        return $range;
    }
1219729
public function set(string $timezone): bool {
    $auth = false;
    try {
      if (!empty($timezone)) {
        date_default_timezone_set($timezone);
        $auth = true;
      }
    } catch (Exception $ex) {
      throw $ex;
    }
    return $auth;
  }
1088982
public function timespan($time = null, $timezone = null)
    {
        // Get translator
        $lang = $this->getTranslator();

        // Create Date instance if needed
        if (!$time instanceof static) {
            $time = Date::parse($time, $timezone);
        }

        $units = [
            'y' => 'year',
            'm' => 'month',
            'w' => 'week',
            'd' => 'day',
            'h' => 'hour',
            'i' => 'minute',
            's' => 'second',
        ];

        // Get DateInterval and cast to array
        $interval = (array) $this->diff($time);

        // Get weeks
        $interval['w'] = (int) ($interval['d'] / 7);
        $interval['d'] = $interval['d'] % 7;

        // Get ready to build
        $str = [];

        // Loop all units and build string
        foreach ($units as $k => $unit) {
            if ($interval[$k]) {
                $str[] = $lang->transChoice($unit, $interval[$k], [':count' => $interval[$k]]);
            }
        }

        return implode(', ', $str);
    }
547687
public function setTimezone($tz)
    {
        if (!$tz instanceof \DateTimeZone) {
            $tz = new \DateTimeZone($tz);
        }

        $this->tz = $tz;

        return parent::setTimezone($tz);
    }