In Drupal 8, views field output uses the field formatters that entities use (Drupal 7 uses its own plugins for this).
The "Today", "Yesterday", "Monday", other functionality cannot be handled by the standard field formatters.
Drupal 8 makes it easy, though, to make new formatters. Make a custom module, and extend DateTimeDefaultFormatter
. Inside this class, you would override the formatDate()
method (and possible the defaultSettings()
one, depending on how fancy you want to be. The method would look something like this
protected function formatDate() {
$timezone = $this->getSetting('timezone_override') ?: $date->getTimezone()->getName();
if ($date is today) {
$output = $this->t('Today, @formatted', [
'@formatted' => $this->dateFormatter->format($date->getTimestamp(), 'custom', 'H:i', $timezone != '' ? $timezone : NULL);
]),
}
else if ($date is yesterday) {
$output = $this->t('Yesterday, @formatted', [
'@formatted' => $this->dateFormatter->format($date->getTimestamp(), 'custom', 'H:i', $timezone != '' ? $timezone : NULL);
]),
}
else if ($date is this week) {
$output = $this->dateFormatter->format($date->getTimestamp(), 'custom', 'D. H:i', $timezone != '' ? $timezone : NULL);
}
else {
$output = $this->dateFormatter->format($date->getTimestamp(), 'custom', 'm/d/y H:i', $timezone != '' ? $timezone : NULL);
}
return $output;
}
You need to work out the logic to choose the proper format. Set the annotation on the formatter properly, and you can use this formatter in the view (or anywhere else).
This should give you a start.