? Language Change ? Pending

User tests: Successful: Unsuccessful:

avatar Harmageddon
Harmageddon
5 Apr 2021

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.relativeFormatted which can be used to display dates in a relative format without losing important information.

Key features:

  • Relative or absolute format is chosen based on user preference.
  • Using the flag $forceRelative, relative display can be forced, ignoring the user's preference (use carefully!).
  • In addition to the relative date display, the full absolute date is shown either in a tooltip or as small text below (like it is currently in the actionlogs / privacy components). This can be deactivated via method parameter.
  • If we use the same format for an absolute display as for the full date (DATE_FORMAT_LC6), it is not displayed twice.

I also added unit tests for the new method.

Testing Instructions

  1. Log in to backend.
  2. In the user menu (top right), click "Edit Account". In the Tab "Basic Settings", you should find a new parameter "Show Relative Dates in Lists" that defaults to true.
  3. Check the following views with this parameter once enabled and once disabled:
    • Module "Latest Actions" on the administrator home dashboard.
    • Module "Logged-in users" on the administrator home dashboard (attention: not yet implemented, only after #32911 is merged and I updated this PR here accordingly)
    • Users - User Actions Log
    • Users - Privacy - Requests: You have to create a new request here if there are none yet.
    • Users - Privacy - Consents: You have to give consent with at least one user beforehand. To do this, enable the plugin "System - Privacy Consent" and log in to frontend with a user account.

Actual result BEFORE applying this Pull Request

joomla-pr-date-relative-below

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.

joomla-pr-date-relative

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

joomla-pr-date-relative-tooltip

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

joomla-pr-date-absolute-below

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

  1. Should we include a default setting for users who have not set this parameter by themselves? Or just default to relative display (the way this PR does it now).
  2. If date display is set to relative, the date format is DATE_FORMAT_LC6, and the date is more than one month in the past, we get the same date twice. The full date tooltip or div does not provide any additional information in this case. Should we try to detect this case or just leave it that way?
  3. Which date format to use for the actions log / privacy components? Currently, it defaults to DATE_FORMAT_LC1, which is "Monday, 05 April 2021". In these list formats, something like DATE_FORMAT_LC5 (2021-05-04 19:00) or DATE_FORMAT_LC6 (2021-05-04 19:00:00) might be better?
  4. Is there a chance to get this in 4.0 or should I directly re-target it to 4.1? In my view, #32910 and #32911 (one already merged into 4.0, one RTC) take away some information from these modules. This PR would "fix" this. But I also see that this might count as a new feature, so 4.1 would be okay as well I guess.
avatar Harmageddon Harmageddon - open - 5 Apr 2021
avatar Harmageddon Harmageddon - change - 5 Apr 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 5 Apr 2021
Category Administration com_users Language & Strings Modules Libraries Unit Tests
avatar Harmageddon Harmageddon - change - 5 Apr 2021
Title
More flexible display of relative dates.
[4.x] More flexible display of relative dates.
avatar Harmageddon Harmageddon - edited - 5 Apr 2021
avatar Harmageddon Harmageddon - change - 5 Apr 2021
Labels Added: ? ? ?
avatar brianteeman
brianteeman - comment - 6 Apr 2021

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

avatar PhilETaylor
PhilETaylor - comment - 6 Apr 2021

image

Is this screenshot wrong? Whats the point of a tool tip that shows the same as the text hovered over?

avatar brianteeman
brianteeman - comment - 6 Apr 2021

BTW I think we used to have this functionality and it was removed

avatar PhilETaylor
PhilETaylor - comment - 6 Apr 2021

Not to kill contributions, but personally, as I have already commented elsewhere:

The home dashboard is an overview of the RECENT happenings on a site therefore it MAKES SENSE that this screen should have relative dates.

On normal listing screens date stamps are better, and can be ordered etc,

And as you have said... "do we really need another option"....

avatar PhilETaylor
PhilETaylor - comment - 6 Apr 2021

Although I do agree a RELATIVE date should have a popover with the full timestamp - that makes sense.

avatar brianteeman
brianteeman - comment - 6 Apr 2021

Although I do agree a RELATIVE date should have a popover with the full timestamp - that makes sense.

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

avatar ChristineWk
ChristineWk - comment - 6 Apr 2021

Although I do agree a RELATIVE date should have a popover with the full timestamp - that makes sense.

Do you mean in this way: Patch: ON, View enabled:

sorry, hv trbls to add screenshot ....

avatar PhilETaylor
PhilETaylor - comment - 6 Apr 2021

I mean like timeago for jQuery has been doing for a decade.

Screenshot 2021-04-06 at 17 16 11

Screenshot 2021-04-06 at 17 14 30

avatar Harmageddon Harmageddon - change - 6 Apr 2021
Labels Added: ?
Removed: ?
avatar Harmageddon
Harmageddon - comment - 6 Apr 2021

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

Done, thank you!

image

Is this screenshot wrong? Whats the point of a tool tip that shows the same as the text hovered over?

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 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

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)".

Not to kill contributions, but personally, as I have already commented elsewhere:

The home dashboard is an overview of the RECENT happenings on a site therefore it MAKES SENSE that this screen should have relative dates.

On normal listing screens date stamps are better, and can be ordered etc,

And as you have said... "do we really need another option"....

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?

avatar Harmageddon Harmageddon - change - 6 Apr 2021
Labels Added: ?
Removed: ?
avatar ChristineWk
ChristineWk - comment - 6 Apr 2021
Although I do agree a RELATIVE date should have a popover with the full timestamp - that makes sense.

Do you mean in this way: Patch: ON, View enabled:

screen shot 2021-04-06 at 18 02 44


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33023.

avatar PhilETaylor
PhilETaylor - comment - 6 Apr 2021

that's what I would expect - yes.

Whenever a relative date is displayed, one should always be able to see the actual date in a popover

I know what 8 mins ago was - that is easy, but when it says 3 weeks ago, I need to know what date that was... that's not easy to quickly do in ones head.

avatar ChristineWk
ChristineWk - comment - 6 Apr 2021

The other point:

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

@ 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:

screen shot 2021-04-06 at 18 16 44


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33023.

avatar BertaOctech BertaOctech - test_item - 8 Apr 2021 - Tested successfully
avatar BertaOctech
BertaOctech - comment - 8 Apr 2021

I have tested this item successfully on 9bbe5e6

This patch works as described.

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.
avatar Harmageddon Harmageddon - change - 10 Apr 2021
Labels Added: ?
Removed: ?
avatar Harmageddon Harmageddon - change - 10 Apr 2021
Labels Added: ?
Removed: ?
avatar dgrammatiko
dgrammatiko - comment - 10 Apr 2021

@Harmageddon sorry but this is not quite ok. Do NOT use HTMLHelper here, use JLayout, eg create a file in layouts/joomla/html/relative-date.php with content:

<?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

avatar dgrammatiko
dgrammatiko - comment - 10 Apr 2021

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
)

avatar michwebdev michwebdev - test_item - 23 Apr 2021 - Tested successfully
avatar michwebdev
michwebdev - comment - 23 Apr 2021

I have tested this item successfully on 9ccc859

This worked. I had to learn about setting up a menu item for Privacy --> Create Request.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33023.

avatar obuisard obuisard - test_item - 23 Apr 2021 - Tested successfully
avatar obuisard
obuisard - comment - 23 Apr 2021

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.

avatar richard67
richard67 - comment - 23 Apr 2021

It's still draft and so tests don't count.

avatar richard67
richard67 - comment - 23 Apr 2021

@Harmageddon @dgrammatiko Is there anything left to be done or clarified regarding the above discussions? Shall I set the "Updates Requested" label?

avatar dgrammatiko
dgrammatiko - comment - 24 Apr 2021

Is there anything left to be done or clarified regarding the above discussions?

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

avatar Harmageddon
Harmageddon - comment - 24 Apr 2021

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.

Shall I set the "Updates Requested" label?

Does that make any difference while the PR is in draft state? If yes, feel free to do so.

avatar richard67
richard67 - comment - 24 Apr 2021

Does that make any difference while the PR is in draft state?

Right, draft state is sufficient.

avatar richard67
richard67 - comment - 12 May 2021

@Harmageddon @wilsonge @bembelimen Would it make sense to move this PR to 4.1?

avatar PhilETaylor
PhilETaylor - comment - 12 May 2021

I never thought something as simple as relative dates could be as controversial as it has been.

Thanks for the link for Intl.RelativeTimeFormat - I have certainly never seen this before, and Regli use JavaScript libraries (timeago.js and jQuery) ones to do this.

avatar Harmageddon
Harmageddon - comment - 16 May 2021

@Harmageddon @wilsonge @bembelimen Would it make sense to move this PR to 4.1?

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.

avatar HLeithner
HLeithner - comment - 27 Jun 2022

This pull request has automatically rebased to 4.2-dev.

avatar drmenzelit
drmenzelit - comment - 21 Oct 2022

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.

avatar drmenzelit drmenzelit - change - 21 Oct 2022
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2022-10-21 11:44:24
Closed_By drmenzelit
Labels Added: ? Language Change ?
Removed: ? ? ?
avatar drmenzelit drmenzelit - close - 21 Oct 2022
avatar brianteeman
brianteeman - comment - 21 Oct 2022

@rdeutz

#PROD2020/024 - There shall be no indiscriminate closing of Issues or Pull Requests
Closing of Issues and Pull requests PR's shall NOT be done without underlying rationale and individual reasoning in the Issue or PR. Elapsing of a time period, inactivity of the submitter are examples that do NOT constitute valid reasons in and by themselves.

avatar rdeutz
rdeutz - comment - 21 Oct 2022

This motion is undicided and the maintainers have decided how we will do the Handling of abandoned PR’s.

The maintainers team will check older (older means, no relevant activity for a certain time frame, 18 months) Pull Requests and discuss if a Pull Request should be closed.

avatar brianteeman
brianteeman - comment - 21 Oct 2022

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

Add a Comment

Login with GitHub to post a comment