@noinspection PhpDocMissingThrowsInspection

Returns a DateTime object based on the timestamp in database format.

@param int|string $timestamp

@return bool|\DateTime
345754
protected function toDateTime($timestamp)
    {
        if (is_numeric($timestamp)) {
            // Unix timestamp.
            $result = new DateTime();
            $result->setTimestamp($timestamp);
        } else {
            // Formatted timestamp, e.g. yyyy-mm-dd hh:mm:ss.
            $result = DateTime::createFromFormat(static::$timestampFormat, $timestamp);
        }
        return $result;
    }
657672
private function checkTimestamp($timestamp)
    {
        if (! $timestamp) {
            throw new Exception(
                'Missing timestamp parameter. The parameter is required'
            );
        }

        // verify that timestamp is recentish
        $now = time();
        if (abs($now - $timestamp) > $this->timestamp_threshold) {
            throw new Exception(
                "Expired timestamp, yours $timestamp, ours $now"
            );
        }
    }
278250
public function date($timestamp = null, $full = true)
    {
        if (!isset($timestamp)) {
            $timestamp = GC_TIME;
        }

        if ($full) {
            $format = $this->config->get('date_full_format', 'd.m.Y H:i');
        } else {
            $format = $this->config->get('date_short_format', 'd.m.y');
        }

        return date($format, $timestamp);
    }
356678
private function timecode(int $timestamp): int
    {
        return (int) floor(($timestamp - $this->getEpoch()) / $this->getPeriod());
    }
554809
public static function roundTimestampToWeek($timestamp)
    {        
        $roundedToDay = self::roundTimestampToDay($timestamp);
        $weekDay  = date('w', $roundedToDay); # 1 = Monday
        $daysToSubtract = $weekDay - 1;
        $roundedToWeek = strtotime("-" . $daysToSubtract . " day", $roundedToDay);
        
        return $roundedToWeek;
    }
491413
static public function fromUnixtime($timestamp=null)
    {
        $timestamp || $timestamp = time();
        if(is_numeric($timestamp)) {
            // strftime format is different from date()
            //$value = strftime('%Y-%m-%d %H:%M:%S', $value);
            $timestamp = strftime('%Y-%m-%d %H:%M:%S', $timestamp);
        }
        return $timestamp;
    }
647358
public static function isValidTimestamp($timestamp, $allowNegative = false)
    {
        $timestamp = (string)$timestamp;

        if ($allowNegative) {
            return ((string)(int)$timestamp === $timestamp)
                && ($timestamp <= PHP_INT_MAX)
                && ($timestamp >= self::MIN_UTC_TIME);
        }

        return ((string)(int)$timestamp === $timestamp)
            && ($timestamp <= PHP_INT_MAX)
            && ($timestamp >= 0);
    }
105382
public function isTimeIncluded($timeStamp)
    {
        // Test the base calendar first. Only if the base calendar not already
        // excludes the time/date, continue evaluating this calendar instance.
        if (false == parent::isTimeIncluded($timeStamp)) {
            return false;
        }

        $date = $this->createDateTime($timeStamp);
        $day = (int) $date->format('j');

        return false == $this->isDayExcluded($day);
    }
966897
public static function unix2dos(int $timestamp = 0) : int
    {
        $timestamp = ($_timestamp == 0) ? getdate() : getdate($_timestamp);

        if ($timestamp['year'] < 1980) return (1 << 21 | 1 << 16);

        $timestamp['year'] -= 1980;

        return ($timestamp['year']    << 25 | $timestamp['mon']     << 21 |
                $timestamp['mday']    << 16 | $timestamp['hours']   << 11 |
                $timestamp['minutes'] << 5  | $timestamp['seconds'] >> 1);
    }
803826
public static function timestampToGermanDateFormat(int $timestamp): string {
        $dateTime = new \DateTime();
        $dateTime->setTimestamp($timestamp);
        $format = $dateTime->format(DateTimeUtil::GERMAN_DATE_TIME_FORMAT);
        return $format;
    }
1149036
private function check_timestamp($timestamp)
    {
        if( ! $timestamp )
            throw new Exception(
                'Missing timestamp parameter. The parameter is required'
            );

        // verify that timestamp is recentish
        $now = time();
        if (abs($now - $timestamp) > $this->timestamp_threshold) {
            throw new Exception(
                "Expired timestamp, yours $timestamp, ours $now"
            );
        }
    }
137971
public function setExpireAt(int $timestamp): bool
    {
        return $this->handle->expireAt($this->name, $timestamp);
    }
774053
protected function timestampHasExpired(int $timestamp): bool
    {
        $date = Carbon::createFromTimestamp($timestamp, 'UTC');
        $start = Carbon::now('UTC')->subSeconds($this->timestampExpires);
        $end = Carbon::now('UTC');

        return !$date->between($start, $end);
    }
534163
public static function getFormatedDate($timestamp)
    {
        return MTimestampHelper::getDay($timestamp) . "." . MTimestampHelper::getMonth($timestamp) . "." . MTimestampHelper::getYear($timestamp);
    }
705473
public function convertTimestampUnixToSoap($timestamp = null) {
        if (is_null($timestamp)) {
            return strftime(self::DATETIME_FORMAT);
        }
        /**
         * @todo: timezone erachter?
         */
        return strftime(self::DATETIME_FORMAT, $timestamp);
    }
1322501
public function build($timestamp = null)
    {
        if (null === $timestamp) {
            $timestamp = new \DateTime();
            $timestamp = $timestamp->format('YmdHis');
        }
        $fileName = sprintf('%s_%s.php', $timestamp, S::underscored($this->migrationName));

        return $fileName;
    }
418793
private function formatTimestampFromApi(array $timestamp)
    {
        $timestamp += [
            'seconds' => 0,
            'nanos' => 0
        ];

        $dt = $this->createDateTimeFromSeconds($timestamp['seconds']);

        return $this->formatTimeAsString($dt, $timestamp['nanos']);
    }