time_in_words()

@param mixed $timestamp
@return
778679
public static function time_in_words($date, $with_time = true) {
        if (!$date) return 'N/A';
        $timestamp = strtotime($date);
        $distance = (round(abs(time() - $timestamp) / 60));

        if ($distance <= 1) {
            $return = ($distance == 0) ? 'a few seconds ago' : '1 minute ago';
        } elseif ($distance < 60) {
            $return = $distance . ' minutes ago';
        } elseif ($distance < 119) {
            $return = 'an hour ago';
        } elseif ($distance < 1440) {
            $return = round(floatval($distance) / 60.0) . ' hours ago';
        } elseif ($distance < 2880) {
            $return = 'Yesterday' . ($with_time ? ' at ' . date('g:i A', $timestamp) : '');
        } elseif ($distance < 14568) {
            $return = date('l, F d, Y', $timestamp) . ($with_time ? ' at ' . date('g:i A', $timestamp) : '');
        } else {
            $return = date('F d ', $timestamp) . ((date('Y') != date('Y', $timestamp) ? ' ' . date('Y', $timestamp) : '')) . ($with_time ? ' at ' . date('g:i A', $timestamp) : '');
        }

        return $return;
    }
70696
public static function elapsedTime($timestamp)
    {
        // @todo: deprecated - use timeDiff instead of this

        $dateDiff = self::timeDiff($timestamp);

        unset ($dateDiff['month']);

        $dateDiff['week'] = floor($dateDiff['days_total'] / 7);
        $dateDiff['day']  = $dateDiff['days_total'] % 7;

        return $dateDiff;
    }
66002
public function setTimestamp($timestamp = 0)
    {
        $this->timestamp = $timestamp;
        if ($timestamp === 0) {
            $this->timestamp = $this->generateTimestamp();
        }
        return $this;
    }
906490
private function _formateMaxLifeTimestamp ($timestamp = 0) {
		$result = [];
		if ($timestamp >= 31557600) {
			$localVal = floor($timestamp / 31557600);
			$result[] = $localVal . ' year' . (($localVal > 1) ? 's' : '');
			if ($localVal > 1) return 'more than ' . $result[0];
			$timestamp = $timestamp - (floor($timestamp / 31557600) * 31557600);
		}
		if ($timestamp >= 2592000) {
			$localVal = floor($timestamp / 2592000);
			$result[] = $localVal . ' month' . (($localVal > 1) ? 's' : '');
			if (count($result) == 1 && $localVal > 1) return 'more than ' . $result[0];
			$timestamp = $timestamp - (floor($timestamp / 2592000) * 2592000);
		}
		if ($timestamp >= 86400) {
			$localVal = floor($timestamp / 86400);
			$result[] = $localVal . ' day' . (($localVal > 1) ? 's' : '');
			if (count($result) == 1 && $localVal > 1) return 'more than ' . $result[0];
			$timestamp = $timestamp - (floor($timestamp / 86400) * 86400);
		}
		if ($timestamp >= 3600) {
			$localVal = floor($timestamp / 3600);
			$result[] = $localVal . ' hour' . (($localVal > 1) ? 's' : '');
			$timestamp = $timestamp - (floor($timestamp / 3600) * 3600);
		}
		if ($timestamp >= 60) {
			$localVal = floor($timestamp / 60);
			$result[] = $localVal . ' minute' . (($localVal > 1) ? 's' : '');
			$timestamp = $timestamp - (floor($timestamp / 60) * 60);
		}
		if ($timestamp > 0) {
			$localVal = floor($timestamp);
			if ($localVal > 1) $result[] = $localVal . ' seconds';
		}
		return implode(', ', $result);
	}
426863
public function setTimestamp($timestamp)
    {
        if (!$timestamp instanceof \DateTime) {
            $date = new \DateTime();
            $date->setTimestamp($timestamp);
        } else {
            $date = $timestamp;
        }
        $this->header['TIMESTAMP'] = $date->format('M d H:i:s');
        return $this;
    }
1371418
protected function getJql($timestamp)
    {
        if (!isset($timestamp)) {
            return $this->jql;
        }

        return $this->jql . " AND updated > '" . date('Y-m-d H:i', $timestamp) . "'";
    }
414099
public static function timeFriendly($timestamp = null)
    {
        if ($timestamp == null) {
            return 'N/A';
        }
        
        // 获取当前时间戳
        $currentTime = time();
        
        // 获取当天0点时间戳
        $todayZero = strtotime('today');
        
        // 获取昨天时间戳
        $yesterday = strtotime('-1 day', $todayZero);
        
        // 获取前天时间戳
        $beforeYesterday = strtotime('-1 day', $yesterday);
        
        // 获取明天0点时间戳
        $tomorrow = strtotime('+1 day', $todayZero);
        
        // 获取后天0点时间戳
        $afterTomorrow = strtotime('+1 day', $tomorrow);
        
        // 获取一天的时间戳
        $oneDayTimestamp = 3600 * 24;
        
        //当年时间戳
        $yearDiff = $currentTime - strtotime("-1 year");
        
        // 时间差
        $timeDiff = $currentTime - $timestamp;
        
        switch (true) {
            case $timestamp >= $afterTomorrow && $timestamp < $afterTomorrow + $oneDayTimestamp :
                return Yii::t('wocenter/app', 'The day after tomorrow {time}', ['time' => date('H:i', $timestamp)]);
            case $timestamp >= $tomorrow && $timestamp < $afterTomorrow :
                return Yii::t('wocenter/app', 'Tomorrow {time}', ['time' => date('H:i', $timestamp)]);
            case $timestamp >= $todayZero && $timestamp < $tomorrow :
                if ($timeDiff < (3600 * 8)) {
                    return Yii::$app->getFormatter()->asRelativeTime($timestamp);
                } else {
                    return Yii::t('wocenter/app', 'Today {time}', ['time' => date('H:i', $timestamp)]);
                }
            case $timestamp >= $yesterday && $timestamp < $todayZero :
                return Yii::t('wocenter/app', 'Yesterday {time}', ['time' => date('H:i', $timestamp)]);
            case $timestamp >= $beforeYesterday && $timestamp < $yesterday :
                return Yii::t('wocenter/app', 'The day before yesterday {time}', ['time' => date('H:i', $timestamp)]);
            default :
                if ($timeDiff > $yearDiff) {
                    return date('Y-m-d H:i', $timestamp);
                } else {
                    return date('m-d H:i', $timestamp);
                }
        }
    }
64808
private function timeAgo($timestamp) {
    $now = new \DateTime('now');
    $date = new \DateTime();
    $date->setTimestamp($timestamp);
    $datediff = date_diff($now, $date);
    $message = '';
    $components = [
      ['y', 'year', 'years'], ['m', 'month', 'months'],
      ['d', 'day', 'days'], ['h', 'hour', 'hours'],
      ['i', 'minute', 'minutes'], ['s', 'second', 'seconds'],
    ];
    foreach ($components as $component) {
      if ($datediff->{$component[0]} > 0) {
        $message = $datediff->{$component[0]} . ' '
          . ($datediff->{$component[0]} > 1 ? t($component[2]) : $component[1]);
        break;
      }
    }
    return !empty($message) ? $message . ' ' . t('ago') : '';
  }
980197
public function timeStamp($timestamp = null) 
     {
        $ts = $timestamp ?: $this->getAttribute("timeStamp");
        if (is_integer($ts) || $ts instanceof TimeWindow) {
            return new TimeWindow(["timeStamp" => $ts]);
        }

        return new TimeWindow();
    }
705473
public function convertTimestampUnixToSoap($timestamp = null) {
        if (is_null($timestamp)) {
            return strftime(self::DATETIME_FORMAT);
        }
        /**
         * @todo: timezone erachter?
         */
        return strftime(self::DATETIME_FORMAT, $timestamp);
    }
751370
public final function last(int $timeStamp = null): string
   {
       if ($timeStamp) {
           $this->lastModification = gmdate(
               "D, d M Y H:i:s",
               $timeStamp) . " GMT";
       }
       return $this->lastModification;
   }
1087525
public function setLastVisit($timestamp = 'now')
	{
		$timestamp = new Date($timestamp);

		$query = $this->getQuery()
			->update($this->getTableName())
			->set(array('lastvisitDate' => $timestamp->toSql()))
			->whereEquals('id', $this->get('id'));

		return $query->execute();
	}
585229
public function setTimestamp($timestamp = null)
    {
        $this->timestamp = $timestamp;
        if ($timestamp === null) {
            $this->timestamp = new Timestamp();
        }
        return $this;
    }
733176
protected function replaceDateTime($string, $timestamp)
    {
        foreach(static::DATE_FORMATS as $format)
        {
            $string = str_replace('{' . $format . '}', date($format, $timestamp), $string);
        }
        return $string;
    }
137971
public function setExpireAt(int $timestamp): bool
    {
        return $this->handle->expireAt($this->name, $timestamp);
    }
771243
public function fromRedisTimestamp($timestamp) : DateTime
    {
        $date = DateTime::createFromFormat('U', $timestamp);
        $date->setTimezone(new DateTimeZone(date_default_timezone_get()));

        return $date;
    }
215225
public static function getDelayedTimestampSize($timestamp)
    {
        $timestamp = self::getTimestamp($timestamp);

        return \Resque::redis()->llen(self::QUEUE_NAME . ':' . $timestamp, $timestamp);
    }