public function formatExtended(string $dateFormat = 'j. F Y', string $timeFormat = 'G:i', $timeZone = null) : string
{
// Sets a custom result time zone if needed
if ($timeZone) {
$this->setTemporaryTimeZone($timeZone);
}
if ($this->dateTime < new \DateTime('midnight - 6 days', $this->dateTime->getTimezone()) || $this->dateTime >= new \DateTime('midnight + 24 hours', $this->dateTime->getTimezone())) {
// Past and future dates
$date = $this->format($dateFormat);
} elseif ($this->dateTime >= new \DateTime('midnight', $this->dateTime->getTimezone())) {
// Today
$date = _('Today');
} elseif ($this->dateTime >= new \DateTime('midnight - 24 hours', $this->dateTime->getTimezone())) {
// Yesterday
$date = _('Yesterday');
} else {
// Last week
static $days = [];
if (empty($days)) {
$days = [_('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), _('Friday'), _('Saturday'), _('Sunday')];
}
$date = $days[$this->dateTime->format('N') - 1];
}
// If no time format is provided, only date will be returned
if (empty($timeFormat)) {
$result = $date;
} else {
// Returns date along with time
$result = $date . ' ' . _('at') . ' ' . $this->dateTime->format($timeFormat);
}
// If a custom result timezone was specified, revert the original one
if ($timeZone) {
$this->revertOriginalTimeZone();
}
return $result;
}