blob: 96ca3a273da404794930ec93778b45fc2a3476cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<?php
use Digitigrade\Model\UserAccount;
use Digitigrade\UserSettings;
function format_datetime(
DateTimeInterface $dt,
DateTimeZone|IntlTimeZone|string|null $tz = null
): string {
static $formatter = new IntlDateFormatter(
get_ui_language(),
IntlDateFormatter::RELATIVE_MEDIUM,
IntlDateFormatter::SHORT
);
static $user = UserAccount::findByCurrentSession();
static $prefs = $user == null ? null : new UserSettings($user);
$formatter->setTimeZone($tz ?? $prefs?->get('locale.timezone') ?? $dt->getTimezone());
return $formatter->format($dt);
}
|