[4.x] More flexible display of relative dates.#33023
[4.x] More flexible display of relative dates.#33023Harmageddon wants to merge 10 commits intojoomla:4.2-devfrom
Conversation
|
Please dont use bootstrap tooltips for this - they are horrible for accessibility. Please look at the way the code is done for the search box and use the pseudo tip code for that |
This comment was marked as abuse.
This comment was marked as abuse.
|
BTW I think we used to have this functionality and it was removed |
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
I think if my memory is correct the problem was that the relative date was only for the first month and after that you got the real date and then the tooltip was a duplicate. But my memory might be tricking me |
Do you mean in this way: Patch: ON, View enabled: sorry, hv trbls to add screenshot .... |
This comment was marked as abuse.
This comment was marked as abuse.
Co-authored-by: Brian Teeman <brian@teeman.net>
Done, thank you!
That's a good point. Technically, it's not the same (in case of absolute formatting and the same date format, the tooltip would not be shown), but it's very close. I added the tooltip for situations where we use a less precise format like the second one you showed here: #33023 (comment)
I don't know if that was the reason back then, but it is an issue, yes (see discussion point 2 in the description). I could try to detect and avoid this case, but then we would have an inconsistency between "two days ago (tooltip: 2021-04-04 19:05:00)" and "2021-02-02 19:00:00 (without tooltip)".
As discussed in #31675, we do need another option, at least for the list case, because different users have different preferences there. Why not use one option for all instead of adding such an option everywhere? |
Do you mean in this way: Patch: ON, View enabled: This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33023. |
This comment was marked as abuse.
This comment was marked as abuse.
|
The other point: @ Harmageddon wrote: I don't know if that was the reason back then, but it is an issue, yes (see discussion point 2 in the description). I could try to detect and avoid this case, but then we would have an inconsistency between "two days ago (tooltip: 2021-04-04 19:05:00)" and "2021-02-02 19:00:00 (without tooltip)". sorry, I can't send screenshot via Github, therefore here: This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33023. |
libraries/src/HTML/Helpers/Date.php
Outdated
| $date, $unit = null, $time = null, $format = null, $forceRelative = false, $showAbsoluteDate = 'tooltip' | ||
| ) |
There was a problem hiding this comment.
| $date, $unit = null, $time = null, $format = null, $forceRelative = false, $showAbsoluteDate = 'tooltip' | |
| ) | |
| $date, $unit = null, $time = null, $format = null, $forceRelative = false, $showAbsoluteDate = 'tooltip') |
There was a problem hiding this comment.
@Quy Hmm, PHPCS has a different opinion about that: https://ci.joomla.org/joomla/joomla-cms/41800/1/6 What is right here?
There was a problem hiding this comment.
If a function definition goes over multiple lines, all lines must be indented with one tab and the closing bracket must go on the same line as the last parameter.
libraries/src/HTML/Helpers/Date.php
Outdated
|
|
||
| if ($showAbsoluteDate === 'below') | ||
| { | ||
| return $dateMain . '<div class="small">' . $dateAbsolute . '</div>'; |
There was a problem hiding this comment.
Is this a custom element? Can't find it anywhere in core or the HTML5 reference. Or are you referring to <time>?
There was a problem hiding this comment.
Yes: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time
Also FYI there's a <small> element also so div and span should be really avoided.
The point of using the proper element is that this text doesn't convey any message for disabled people but time does.
There was a problem hiding this comment.
Better like this?
libraries/src/HTML/Helpers/Date.php
Outdated
|
|
||
| if ($showAbsoluteDate === 'tooltip') | ||
| { | ||
| return '<span>' . $dateMain . '</span><div role="tooltip">' . $dateAbsolute . '</div>'; |
There was a problem hiding this comment.
Do you have an alternative suggestion? Always displaying the full date below the relative one might lead to crowded layouts in some cases, and confuse rather than help users. And not displaying this additional information at all seem worse to me than a tooltip.
libraries/src/HTML/Helpers/Date.php
Outdated
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public static function relativeFormatted( | ||
| $date, $unit = null, $time = null, $format = null, $forceRelative = false, $showAbsoluteDate = 'tooltip' |
There was a problem hiding this comment.
Any function with more than 4 arguments is realistically unusable (nobody will ever remember 6 params in a row, never).
Also if you want to have Bootstrap mixed here I would suggest creating a JLayout instead of an HTMLHelper. HTMLHelpers need a plugin for an override, JLayouts not and because not everybody is happy with BS easy overriding is better for the future of the project
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
There was a problem hiding this comment.
Dude, it's not about IDE's it's about WRONG patterns, according to everybody in the business before we were even born (ref: https://softwareengineering.stackexchange.com/a/145073 )
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
There was a problem hiding this comment.
Any function with more than 4 arguments is realistically unusable (nobody will ever remember 6 params in a row, never).
True. But my goal was to create a rather generic function that can be used in various places throughout the core for different displays of dates. I could rearrange the parameters, so the (expectedly) less used parameters can be omitted and use default values.
Also if you want to have Bootstrap mixed here I would suggest creating a JLayout instead of an HTMLHelper. HTMLHelpers need a plugin for an override, JLayouts not and because not everybody is happy with BS easy overriding is better for the future of the project
Following the suggestion of Brian above, there is no Bootstrap anymore in this PR.
|
I have tested this item ✅ successfully on 9bbe5e6 After applying the patch a new option appears in the User Profile. When "Show Relative Dates in Lists = NO" is selected, the dates in the action logs appear as absolute dates. Otherwise they appear as relative dates. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33023. |
Co-authored-by: Quy <quy@fluxbb.org>
|
@Harmageddon sorry but this is not quite ok. Do NOT use HTMLHelper here, use JLayout, eg create a file in <?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
defined('_JEXEC') or die;
extract($displayData);
/**
* Layout variables
* -----------------
* @var boolean $forceRelative
* @var string $format
* @var string $date
* @var string $showAbsoluteDate
* @var string $unit
* @var string $time
*/
$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')
{
echo '<span>' . $dateMain . '</span><time role="tooltip">' . $dateAbsolute . '</time>';
}
if ($showAbsoluteDate === 'below')
{
echo $dateMain . '<time class="small d-block">' . $dateAbsolute . '</time>';
}
echo $dateMain;and then call it like: <?php echo \Joomla\CMS\Layout\LayoutHelper::render(
'joomla.html.relative-date',
[
'date' => $item->log_date,
'format' => Text::_('DATE_FORMAT_LC5'),
$showAbsoluteDate = 'tooltip',
$time = $now,
$forceRelative = false,
$unit = null
]
); ?>The reason is simple: using JLayout is easily overridable for front end devs. HTMLHelper need a plugin in order to be overriden |
|
Actually, reading #33023 (comment) I think the idea of processing this data in the server is wrong, should be done on the client-side using Temporal: https://github.com/tc39/proposal-temporal and a simple web component. Sorry, the JS is not temporal but https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat Actually @PhilETaylor I think your PR that introduced the relative dates is wrong, we can do this using the browser native power... ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat |
| <?php echo $item->body; ?> | ||
| </td> | ||
| <td class="break-word"> | ||
| <?php echo HTMLHelper::_('date.relative', new Date($item->created), null, $now); ?> |
There was a problem hiding this comment.
Please delete use Joomla\CMS\Date\Date;
|
I have tested this item ✅ successfully on 9ccc859 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33023. |
|
I have tested this item ✅ successfully on 9ccc859 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33023. |
|
It's still draft and so tests don't count. |
|
@Harmageddon @dgrammatiko Is there anything left to be done or clarified regarding the above discussions? Shall I set the "Updates Requested" label? |
I'll stick to my opinion that this should NOT be an HTMLHelper thing but a JLayout, HTMLHelper should be used only for PHP functionality, if anything is echoed then that should be done directly with Layouts |
|
I see the point in making it a layout, but haven't found the time yet to convert and test it. I'm not sure about the web component proposal though, because apart from shifting the translation from our own translation files to the browser, I don't see great advantages, as we need to do the same calculations as far as I understand. Thank you for testing this already, but as @richard67 said, this is still in draft state because of the discussions and open points listed above. As soon as it is ready for testing, I'm going to mark it as such.
Does that make any difference while the PR is in draft state? If yes, feel free to do so. |
Right, draft state is sufficient. |
|
@Harmageddon @wilsonge @bembelimen Would it make sense to move this PR to 4.1? |
This comment was marked as abuse.
This comment was marked as abuse.
As I sadly don't have the time right now to proceed with this, I assume it's not going to make it into 4.0. So yes, I'd re-target this for 4.1 and come up with a more consistent and overridable solution when I find the time. |
|
This pull request has automatically rebased to 4.2-dev. |
|
The feature is interesting, but due to inactivity we are closing this draft. You can open it again, when you have the time to rework it. |
|
|
This motion is undicided and the maintainers have decided how we will do the Handling of abandoned PR’s.
|
My apologies - I missed thaat part |



Summary of Changes
This is an alternative solution to #31675 and fixes the concerns discussed in #32911 (comment) and the following comments.
This PR introduces a new HTMLHelper method called
date.relativeFormattedwhich can be used to display dates in a relative format without losing important information.Key features:
$forceRelative, relative display can be forced, ignoring the user's preference (use carefully!).I also added unit tests for the new method.
Testing Instructions
Actual result BEFORE applying this Pull Request
The dates in the mentioned components and modules are relative for dates which are more recent than a month. For user actions log and the privacy views, the full date is displayed below the relative date.
For the dashboard modules, the full date is not shown anywhere.
Expected result AFTER applying this Pull Request
With "Show Relative Dates in Lists" enabled
In the dashboard modules, the relative dates have a tooltip now showing the full exact date of the action.
In the actions log and privacy views, the display is the same as before.
With "Show Relative Dates in Lists" disabled
Dates in the mentioned locations are displayed in an absolute format. The full date and time is shown below or in the tooltip, respectively.
Documentation Changes Required
Maybe we need to document this user parameter somewhere?
Open Discussion Points