Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
Expand All @@ -26,6 +27,7 @@
$wa->useScript('keepalive')
->useScript('com_actionlogs.admin-actionlogs');

$now = Factory::getDate();
?>

<form action="<?php echo Route::_('index.php?option=com_actionlogs&view=actionlogs'); ?>" method="post" name="adminForm" id="adminForm">
Expand Down Expand Up @@ -86,10 +88,7 @@
<?php echo $this->escape(Text::_($extension)); ?>
</td>
<td class="d-none d-md-table-cell">
<?php echo HTMLHelper::_('date.relative', $item->log_date); ?>
<div class="small">
<?php echo HTMLHelper::_('date', $item->log_date, Text::_('DATE_FORMAT_LC6')); ?>
</div>
<?php echo HTMLHelper::_('date.relativeFormatted', $item->log_date, Text::_('DATE_FORMAT_LC1'), 'below', $now); ?>
</td>
<td class="d-md-table-cell">
<?php echo $this->escape($item->name); ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@
<?php echo $item->body; ?>
</td>
<td class="break-word">
<?php echo HTMLHelper::_('date.relative', new Date($item->created), null, $now); ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete use Joomla\CMS\Date\Date;

<div class="small">
<?php echo HTMLHelper::_('date', $item->created, Text::_('DATE_FORMAT_LC6')); ?>
</div>
<?php echo HTMLHelper::_('date.relativeFormatted', $item->created, Text::_('DATE_FORMAT_LC1'), 'below', $now); ?>
</td>
<td>
<?php echo (int) $item->id; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@
<?php echo Text::_('COM_PRIVACY_HEADING_REQUEST_TYPE_TYPE_' . $item->request_type); ?>
</td>
<td>
<?php echo HTMLHelper::_('date.relative', $itemRequestedAt, null, $now); ?>
<div class="small">
<?php echo HTMLHelper::_('date', $item->requested_at, Text::_('DATE_FORMAT_LC6')); ?>
</div>
<?php echo HTMLHelper::_('date.relativeFormatted', $itemRequestedAt, Text::_('DATE_FORMAT_LC1'), 'below', $now); ?>
</td>
<td>
<?php echo (int) $item->id; ?>
Expand Down
11 changes: 11 additions & 0 deletions administrator/components/com_users/forms/user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@
<option value="">JOPTION_USE_DEFAULT</option>
</field>

<field
name="use_relative_dates"
type="radio"
label="COM_USERS_USER_FIELD_USE_RELATIVE_DATES_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

</fieldset>
<!-- User accessibility settings -->
<fieldset name="accessibility" label="COM_USERS_A11Y_SETTINGS_FIELDSET_LABEL">
Expand Down
1 change: 1 addition & 0 deletions administrator/language/en-GB/com_users.ini
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ COM_USERS_USER_FIELD_RESETCOUNT_LABEL="Password Reset Count"
COM_USERS_USER_FIELD_SENDEMAIL_LABEL="Receive System Emails"
COM_USERS_USER_FIELD_TIMEZONE_LABEL="Time Zone"
COM_USERS_USER_FIELD_TWOFACTOR_LABEL="Authentication Method"
COM_USERS_USER_FIELD_USE_RELATIVE_DATES_LABEL="Show Relative Dates in Lists"
COM_USERS_USER_FIELD_USERNAME_LABEL="Login Name (Username)"
COM_USERS_USER_FORM_EDIT="Edit User"
COM_USERS_USER_FORM_NEW="New User"
Expand Down
4 changes: 3 additions & 1 deletion administrator/modules/mod_latestactions/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;

$now = Factory::getDate();
?>
<table class="table" id="<?php echo str_replace(' ', '', $module->title) . $module->id; ?>">
<caption class="visually-hidden"><?php echo $module->title; ?></caption>
Expand All @@ -29,7 +31,7 @@
<?php echo $item->message; ?>
</td>
<td>
<?php echo HTMLHelper::_('date.relative', $item->log_date); ?>
<?php echo HTMLHelper::_('date.relativeFormatted', $item->log_date, Text::_('DATE_FORMAT_LC5'), 'tooltip', $now); ?>
</td>
</tr>
<?php endforeach; ?>
Expand Down
60 changes: 60 additions & 0 deletions libraries/src/HTML/Helpers/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
\defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Date\Date as DateHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\User\User;

/**
* Extended Utility class for handling date display.
Expand Down Expand Up @@ -90,4 +92,62 @@ public static function relative($date, $unit = null, $time = null, $format = nul
// Over a month, return the absolute time
return HTMLHelper::_('date', $date, $format);
}

/**
* Converts a given date into relative or absolute format, depending on user preference, and displays it along with the full date.
*
* @param string $date The date to convert
* @param string|null $format An optional format for the HTMLHelper::date output. Used if the date display should be absolute,
* either because of user settings or because it is too far in the past for relative display.
* @param string $showAbsoluteDate One of:
* - 'tooltip': Display the full date in a tooltip.
* - 'below': Display the full date below the relative date.
* - 'hide': Don't display the full date.
*
* @param string|null $time An optional time to compare to, defaults to now.
* @param bool $forceRelative Whether to force relative date display, regardless of user preference.
* @param string|null $unit The optional unit of measurement to return if the value of the diff is greater than one.
* Only applies to relative display.
*
* @return string The relative or absolute date, plus the full date if applicable.
*
* @since __DEPLOY_VERSION__
*/
public static function relativeFormatted(
$date, $format = null, $showAbsoluteDate = 'tooltip', $time = null, $forceRelative = false, $unit = null)
{
$user = Factory::getApplication()->getIdentity();

if ($user === null)
{
$useRelative = true;
}
else
{
$useRelative = $forceRelative || $user->getParam('use_relative_dates', true);
}

// Format for the full / absolute date display.
$formatAbsolute = Text::_('DATE_FORMAT_LC6');

if (!$useRelative && $format === $formatAbsolute)
{
return HTMLHelper::_('date', $date, $format);
}

$dateMain = $useRelative ? HTMLHelper::_('date.relative', $date, $unit, $time, $format) : HTMLHelper::_('date', $date, $format);
$dateAbsolute = HTMLHelper::_('date', $date, $formatAbsolute);

if ($showAbsoluteDate === 'tooltip')
{
return '<span>' . $dateMain . '</span><time role="tooltip">' . $dateAbsolute . '</time>';
}

if ($showAbsoluteDate === 'below')
{
return $dateMain . '<time class="small d-block">' . $dateAbsolute . '</time>';
}

return $dateMain;
}
}
Loading