mirror of
https://github.com/humhub/humhub.git
synced 2025-03-04 07:08:58 +01:00
Enh: Timeago added optional fullDate formatting callback
This commit is contained in:
parent
5354c1d063
commit
069ea895c1
@ -145,7 +145,11 @@ $config = [
|
||||
'timeAgoStatic' => false,
|
||||
// Seconds before hide time from timeago date
|
||||
// Set to false to always display time
|
||||
'timeAgoHideTimeAfter' => 259200,
|
||||
'timeAgoHideTimeAfter' => 259200,
|
||||
// Optional: Callback for TimageAgo FullDateFormat
|
||||
//'timeAgoFullDateCallBack' => function($timestamp) {
|
||||
// return 'formatted';
|
||||
//}
|
||||
],
|
||||
'humhub' => [
|
||||
// Marketplace / New Version Check
|
||||
|
@ -68,8 +68,6 @@ class TimeAgo extends \yii\base\Widget
|
||||
|
||||
$this->getView()->registerJs('$(".time").timeago();', \yii\web\View::POS_END, 'timeago');
|
||||
return '<span class="time" title="' . $this->timestamp . '">' . $this->getFullDateTime() . '</span>';
|
||||
|
||||
#$date = Yii::$app->formatter->asRelativeTime($this->timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,11 +78,11 @@ class TimeAgo extends \yii\base\Widget
|
||||
*/
|
||||
public function renderDateTime($elapsed)
|
||||
{
|
||||
$date = Yii::$app->formatter->asDate($this->timestamp, 'medium');
|
||||
|
||||
// Show time when within specified range
|
||||
if (Yii::$app->params['formatter']['timeAgoHideTimeAfter'] === false || $elapsed < Yii::$app->params['formatter']['timeAgoHideTimeAfter']) {
|
||||
$date .= " " . Yii::$app->formatter->asTime($this->timestamp, 'short');
|
||||
if (Yii::$app->params['formatter']['timeAgoHideTimeAfter'] === false || $elapsed <= Yii::$app->params['formatter']['timeAgoHideTimeAfter']) {
|
||||
$date = $this->getFullDateTime();
|
||||
} else {
|
||||
$date = Yii::$app->formatter->asDate($this->timestamp, 'medium');
|
||||
}
|
||||
|
||||
return '<span class="time"><span title="' . $this->getFullDateTime() . '">' . $date . '</span></span>';
|
||||
@ -97,7 +95,11 @@ class TimeAgo extends \yii\base\Widget
|
||||
*/
|
||||
protected function getFullDateTime()
|
||||
{
|
||||
return Yii::$app->formatter->asDate($this->timestamp, 'full') . ' - ' . Yii::$app->formatter->asTime($this->timestamp, 'short');
|
||||
if (isset(Yii::$app->params['formatter']['timeAgoFullDateCallBack']) && is_callable(Yii::$app->params['formatter']['timeAgoFullDateCallBack'])) {
|
||||
return call_user_func(Yii::$app->params['formatter']['timeAgoFullDateCallBack'], $this->timestamp);
|
||||
}
|
||||
|
||||
return Yii::$app->formatter->asDate($this->timestamp, 'medium') . ' - ' . Yii::$app->formatter->asTime($this->timestamp, 'short');
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user