From 38b18b4a59e30b053469db52b4f1d5c2835dfae1 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Mon, 19 Aug 2024 14:32:33 +0200 Subject: [PATCH] Fix outdated usage of `DateUtil::format()` in user list --- .../install/files/acp/templates/userList.tpl | 4 +-- .../files/lib/acp/page/UserListPage.class.php | 31 +++++-------------- .../data/custom/option/CustomOption.class.php | 11 ++++--- .../files/lib/data/user/User.class.php | 11 +++++++ 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/userList.tpl b/wcfsetup/install/files/acp/templates/userList.tpl index b76cbc4ebd..8e4bdcd299 100644 --- a/wcfsetup/install/files/acp/templates/userList.tpl +++ b/wcfsetup/install/files/acp/templates/userList.tpl @@ -215,8 +215,8 @@ {if $user->isOnline()} {lang}wcf.user.online{/lang} - {else} - {if $columnValues[$user->userID][$column]|isset}{@$columnValues[$user->userID][$column]}{/if} + {elseif $user->lastActivityTime} + {time time=$user->lastActivityTime} {/if} {else} diff --git a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php index a583bd5c12..da8ee25207 100755 --- a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php @@ -16,7 +16,6 @@ use wcf\system\option\IOptionHandler; use wcf\system\option\user\IUserOptionOutput; use wcf\system\request\LinkHandler; use wcf\system\WCF; -use wcf\util\DateUtil; use wcf\util\StringUtil; /** @@ -320,32 +319,16 @@ class UserListPage extends SortablePage break; case 'registrationDate': - $this->columnValues[$user->userID][$column] = DateUtil::format( - DateUtil::getDateTimeByTimestamp($user->{$column}), - DateUtil::DATE_FORMAT + $this->columnValues[$user->userID][$column] = \IntlDateFormatter::formatObject( + WCF::getUser()->getLocalDate($user->{$column}), + [ + \IntlDateFormatter::LONG, + \IntlDateFormatter::NONE, + ], + WCF::getLanguage()->getLocale() ); break; - case 'lastActivityTime': - if ($user->{$column}) { - $this->columnValues[$user->userID][$column] = \str_replace( - '%time%', - DateUtil::format( - DateUtil::getDateTimeByTimestamp($user->{$column}), - DateUtil::TIME_FORMAT - ), - \str_replace( - '%date%', - DateUtil::format( - DateUtil::getDateTimeByTimestamp($user->{$column}), - DateUtil::DATE_FORMAT - ), - WCF::getLanguage()->get('wcf.date.dateTimeFormat') - ) - ); - } - break; - case 'profileHits': case 'activityPoints': case 'likesReceived': diff --git a/wcfsetup/install/files/lib/data/custom/option/CustomOption.class.php b/wcfsetup/install/files/lib/data/custom/option/CustomOption.class.php index 8111178cdf..728d5abc82 100644 --- a/wcfsetup/install/files/lib/data/custom/option/CustomOption.class.php +++ b/wcfsetup/install/files/lib/data/custom/option/CustomOption.class.php @@ -9,7 +9,6 @@ use wcf\system\bbcode\MessageParser; use wcf\system\bbcode\SimpleMessageParser; use wcf\system\exception\NotImplementedException; use wcf\system\WCF; -use wcf\util\DateUtil; use wcf\util\OptionUtil; use wcf\util\StringUtil; @@ -153,9 +152,13 @@ abstract class CustomOption extends Option implements ITitledObject $day = \intval($optionValue[2]); } - return DateUtil::format( - DateUtil::getDateTimeByTimestamp(\gmmktime(12, 1, 1, $month, $day, $year)), - DateUtil::DATE_FORMAT + return \IntlDateFormatter::formatObject( + WCF::getUser()->getLocalDate(\gmmktime(12, 1, 1, $month, $day, $year)), + [ + \IntlDateFormatter::LONG, + \IntlDateFormatter::NONE, + ], + WCF::getLanguage()->getLocale() ); case 'float': diff --git a/wcfsetup/install/files/lib/data/user/User.class.php b/wcfsetup/install/files/lib/data/user/User.class.php index 07dc5a769f..1d6d47b598 100644 --- a/wcfsetup/install/files/lib/data/user/User.class.php +++ b/wcfsetup/install/files/lib/data/user/User.class.php @@ -466,6 +466,17 @@ final class User extends DatabaseObject implements IPopoverObject, IRouteControl return $this->timezoneObj; } + /** + * Applies the user's timezone to the given timestamp. + */ + public function getLocalDate(int $timestamp): \DateTimeImmutable + { + $dateTime = (new \DateTimeImmutable('@' . $timestamp)); + $dateTime = $dateTime->setTimezone($this->getTimeZone()); + + return $dateTime; + } + /** * Returns a list of users. * -- 2.20.1