akeeba / engage

Akeeba Engage - Comments for Joomla!™ articles made easy
GNU General Public License v3.0
16 stars 10 forks source link

Wrong time in module mod_engage_latest #202

Closed pinochico closed 2 years ago

pinochico commented 2 years ago

Time for comment is saved to DB in UTC (Gibraltar) format.

Etc. 21:35:46

But in Joomla global setup (or in user who created comment) is setup for 'offset' == TimeZone => Prague (UTC+2)

Modul show still time in UTC, not as 23:35:46.

But time for comment bottom article is with right TimeZone (yep, because in HtmlView.php for components/com_engage/tmpl/comments/default_list.php is a lot's function for right TimeZone, but in tmpl for module not).

My Idea:

  1. Add code to USE section (top in template modules/mod_engage_latest/tmpl/default.php)
//Fix
use Akeeba\Component\Engage\Administrator\Helper\UserFetcher;
use Joomla\CMS\Date\Date;
use Joomla\CMS\User\User;
use DateTimeZone;
  1. Add code for calculate right datetime:
//Fix
$user = !empty($comment->created_by) && empty($comment->name) ? UserFetcher::getUser($comment->created_by) : new User();
$siteTimezone = Factory::getApplication()->get('offset', 'UTC');
$zone = $user->guest ? $siteTimezone : $user->getParam('timezone', $siteTimezone);
$user->userTimezone = new DateTimeZone($zone);
$commentDate   = (new Date($comment->created))->setTimezone($user->userTimezone);
//END
  1. change code for show datetime:4.

$commentDate->format(Text::_('DATE_FORMAT_LC2'), true)

Result you can see on:

https://joomla4.easy.minion.cz/?view=article&id=1:clanek-cs-cz&catid=8

System information

Engage v. 3.0.9 Module Engage Latest v. 3.0.9

Mandatory information

Issues without this information can not and will not be replied to.

You can skip some or all of this information. However, the more information you provide the faster and better we can help.

nikosdion commented 2 years ago

Addressed with commit https://github.com/akeeba/engage/commit/3595191140b9a273dcf0180f33ebf843fa933185