public static timeElapsed ( string $fromTime = null, boolean $human = true, string $toTime = null, string $append = null ) : string | ||
$fromTime | string | start date time |
$human | boolean | if true returns an approximate human friendly output. If set to `false`, will attempt an exact conversion of time intervals. |
$toTime | string | end date time (defaults to current system time) |
$append | string | the string to append for the converted elapsed time. Defaults to ' ago'. Example Output(s): 10 hours ago |
Résultat | string |
public static function timeElapsed($fromTime = null, $human = true, $toTime = null, $append = null)
{
static::initI18N();
if ($append === null) {
$append = ' ' . Yii::t('kvenum', 'ago');
}
if ($fromTime != null) {
$fromTime = strtotime($fromTime);
$toTime = $toTime == null ? time() : (int) $toTime;
}
return static::timeInterval($toTime - $fromTime, $append, $human);
}
public function data() { $userField = $this->userField; $output = ''; $models = Chat::records(); if ($models) foreach ($models as $model) { if (isset($model->user->$userField)) { $avatar = $model->user->$userField; } else{ $avatar = Yii::$app->assetManager->getPublishedUrl("@vendor/sintret/yii2-chat-adminlte/assets/img/avatar.png"); } $output .= '<div class="item"> <img class="online" alt="user image" src="' . $avatar . '"> <p class="message"> <a class="name" href="#"> <small class="text-muted pull-right" style="color:green"><i class="fa fa-clock-o"></i> ' . \kartik\helpers\Enum::timeElapsed($model->updateDate) . '</small> ' . $model->user->user_name . ' </a> ' . $model->message . ' </p> </div>'; } return $output; }