public function OpignoMessageThread::getMessageFormattedDate in Opigno messaging 3.x
Get the formatted date of the message.
Parameters
\Drupal\private_message\Entity\PrivateMessage $message: The private message entity to get the date for.
Return value
\Drupal\Core\StringTranslation\TranslatableMarkup|string The message formatted date.
1 call to OpignoMessageThread::getMessageFormattedDate()
- OpignoMessageThread::getThreadDisplayData in src/
Services/ OpignoMessageThread.php - Get the messages thread data: image, title, date, text.
File
- src/
Services/ OpignoMessageThread.php, line 270
Class
- OpignoMessageThread
- The private messages manager service.
Namespace
Drupal\opigno_messaging\ServicesCode
public function getMessageFormattedDate(PrivateMessage $message) {
$timestamp = $message
->getCreatedTime();
switch ($timestamp) {
// If the message was created today, the format should be: "today - h:m".
case $timestamp >= strtotime('today'):
$time = $this->dateFormatter
->format($timestamp, 'hour_minute');
$created = $this
->t('today - @time', [
'@time' => $time,
]);
break;
// If the message was sent yesterday, the format should be:
// "yesterday - h:m".
case $timestamp >= strtotime('yesterday'):
$time = $this->dateFormatter
->format($timestamp, 'hour_minute');
$created = $this
->t('yesterday - @time', [
'@time' => $time,
]);
break;
// For older messages display the full date with the time.
default:
$created = $this->dateFormatter
->format($timestamp, 'date_short_with_time');
}
return $created;
}