Fix outdated usage of `DateUtil::format()` in user list
authorMarcel Werk <burntime@woltlab.com>
Mon, 19 Aug 2024 12:32:33 +0000 (14:32 +0200)
committerMarcel Werk <burntime@woltlab.com>
Mon, 19 Aug 2024 12:32:33 +0000 (14:32 +0200)
wcfsetup/install/files/acp/templates/userList.tpl
wcfsetup/install/files/lib/acp/page/UserListPage.class.php
wcfsetup/install/files/lib/data/custom/option/CustomOption.class.php
wcfsetup/install/files/lib/data/user/User.class.php

index b76cbc4ebd62c48bdd3b61b1bf0b821dbeded61e..8e4bdcd2999e099a0d86d862c8e1c9cf858fc161 100644 (file)
                                                                        {if $user->isOnline()}
                                                                                {lang}wcf.user.online{/lang}
                                                                                <span class="userOnlineIndicator" aria-hidden="true"></span>
-                                                                       {else}
-                                                                               {if $columnValues[$user->userID][$column]|isset}{@$columnValues[$user->userID][$column]}{/if}
+                                                                       {elseif $user->lastActivityTime}
+                                                                               {time time=$user->lastActivityTime}
                                                                        {/if}
                                                                </td>
                                                        {else}
index a583bd5c12be28d0a2a3f146685c7f8faff6bcd3..da8ee25207da978c5e4e35ee474c5015162a05aa 100755 (executable)
@@ -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':
index 8111178cdf01dccdc7debd6c54a53eb947046795..728d5abc820c8dc2f6a595fc48779e65794b8662 100644 (file)
@@ -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':
index 07dc5a769f5d4b6bb5bf6c7bb247e7b448103eb5..1d6d47b598dd99074571ab26c26df84058519814 100644 (file)
@@ -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.
      *