• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/user.php
  • Класс: CAllUser
  • Вызов: CAllUser::FormatLastActivityDate
static function FormatLastActivityDate($timestamp, $now = false)
{
	global $DB;

	if ($timestamp instanceof MainTypeDateTime)
	{
		$timestamp = $timestamp->getTimestamp();
	}
	else
	{
		if (is_int($timestamp))
		{
			$timestamp = intval($timestamp);
		}
		else
		{
			return '';
		}
	}

	if ($now === false)
	{
		$now = time();
	}
	else
	{
		if ($now instanceof MainTypeDateTime)
		{
			$now = $now->getTimestamp();
		}
		else
		{
			$now = intval($now);
		}
	}

	$ampm = IsAmPmMode(true);
	$timeFormat = ($ampm === AM_PM_LOWER ? "g:i a" : ($ampm === AM_PM_UPPER ? "g:i A" : "H:i"));

	$formattedDate = FormatDate([
		"tomorrow" => "#01#{$timeFormat}",
		"now" => "#02#",
		"todayFuture" => "#03#{$timeFormat}",
		"yesterday" => "#04#{$timeFormat}",
		"-" => preg_replace('/:s$/', '', $DB->DateFormatToPHP(CSite::GetDateFormat())),
		"s60" => "sago",
		"i60" => "iago",
		"H5" => "Hago",
		"H24" => "#03#{$timeFormat}",
		"d31" => "dago",
		"m12>1" => "mago",
		"m12>0" => "dago",
		'' => "#05#",
	], $timestamp, $now);

	if (preg_match('/^#(d+)#(.*)/', $formattedDate, $match))
	{
		switch ($match[1])
		{
			case "01":
				$formattedDate = str_replace("#TIME#", $match[2], GetMessage('USER_LAST_SEEN_TOMORROW'));
				break;
			case "02":
				$formattedDate = GetMessage('USER_LAST_SEEN_NOW');
				break;
			case "03":
				$formattedDate = str_replace("#TIME#", $match[2], GetMessage('USER_LAST_SEEN_TODAY'));
				break;
			case "04":
				$formattedDate = str_replace("#TIME#", $match[2], GetMessage('USER_LAST_SEEN_YESTERDAY'));
				break;
			case "05":
				$formattedDate = GetMessage('USER_LAST_SEEN_MORE_YEAR');
				break;
			default:
				$formattedDate = $match[2];
				break;
		}
	}

	return $formattedDate;
}