? Success

User tests: Successful: Unsuccessful:

avatar infograf768
infograf768
8 Aug 2015

When using the Profile User Plugin, the date of birth entered and displayed should be independent from server or user settings.

Test instructions:

In Global Configuration set the Server Time Zone to Paris (Test done in France, use other values to test)
Enable User - Profile plugin
Edit com_contacts Options =>Contact tab and enable "Show Profile"

In back-end, create a contact and assign it to a user.
Edit the user profile:
1. Set the Time Zone to "Default" in Basic Settings tab
2. Set a Date of birth in "User Profile" tab with the calendar. I have set it to 1948-04-20 below.
3. Create a menu item to display this contact in frontend. Display the Profile tab or slider of that contact.

Before patch, the date of birth is wrong, it displays 1948-04-19:
screen shot 2015-07-30 at 13 24 33

After patch, as it takes off the server-utc filter, the date is correct.
screen shot 2015-08-08 at 11 39 07

Will prepare another patch to display the date in the correct language format (DATE_FORMAT_LC4), without the time, i.e. to get for French:
screen shot 2015-08-08 at 12 06 31

avatar infograf768 infograf768 - open - 8 Aug 2015
avatar infograf768 infograf768 - change - 8 Aug 2015
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 8 Aug 2015
Labels Added: ?
avatar infograf768 infograf768 - change - 8 Aug 2015
Category Front End Plugins
avatar infograf768 infograf768 - change - 8 Aug 2015
Title
User Profile: Date of birth should be absolute.
User Profile: Date of birth should be absolute.
avatar Bakual
Bakual - comment - 8 Aug 2015

Sorry, but that will make it even worse. By default the filter will be "USER_UTC", adjusting the date when showing to the timezone of the user.
Having the filter as "SERVER_UTC" works fine. The real issue is that you have changed that timezone after the first date has been entered.

If we really want to have this date stored as is, then we need to change the code so it isn't stored as UTC in the database and always shows as it was entered. I doubt you can do that in a B/C way.

avatar infograf768
infograf768 - comment - 9 Aug 2015

Have you tested that? In my instructions I specified to set the user time zone to "Default" and I evidently resaved the user profile each time I modified the global Server time zone.

When server set to Paris, dob entered as 1948-04-20 in the profile field through calendar or manually, I get in the frontend:
1948-04-19 23:00:00
Database contains also 1948-04-19 23:00:00

avatar infograf768
infograf768 - comment - 9 Aug 2015

I tested also by setting the server to Moscow and I get
1948-04-19 21:00:00

To test your comment, I applied my patch, set the server to Moscow, the user to Paris, and re-entered the correct dob for the user profile.
It saves as "1948-04-20 00:00:00" in the db and displays as 1948-04-20 00:00:00 in front-end, which is what is expected.

We do have a bug, Thomas and my patch looks like working.

avatar infograf768
infograf768 - comment - 9 Aug 2015
avatar Bakual
Bakual - comment - 9 Aug 2015

See:
https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/form/fields/calendar.php#L175-L206
As coded, no filter does not mean it falls down to user_utc

You need to look a few lines above:
https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/form/fields/calendar.php#L125
$this->filter = (string) $this->element['filter'] ? (string) $this->element['filter'] : 'USER_UTC';

I haven't tested, but since I rewrote that calendar field sometimes ago, I think I know how it's supposed to work.
If it doesn't change the value of the date, then we actually have a bug there :smile:
server_utc is the filter which is meant to not change the date since you are not expected to change that setting after you set up the server.

avatar Bakual
Bakual - comment - 9 Aug 2015

To test your comment, I applied my patch, set the server to Moscow, the user to Paris, and re-entered the correct dob for the user profile.
It saves as "1948-04-20 00:00:00" in the db and displays as 1948-04-20 00:00:00 in front-end, which is what is expected.

To test you should enter the date, and afterwards change the timezone of the user. AS long as the timezone is the same as when the value is entered, it will shown the same. It's when you change the timezone afterwards when it gets interesting :smile:

avatar infograf768
infograf768 - comment - 9 Aug 2015

Hmm, yeah, if I change again the user_utc to Moscow, then it fails again.

We do have a bug indeed and imho we need to code a no-filter param for the date.

avatar Bakual
Bakual - comment - 9 Aug 2015

Nah, server_utc would work. As long as you don't change the server timezone.
Which there really is no point in changing after you setup the site. It's the whole purpose of that filter as I understand it.

avatar infograf768
infograf768 - comment - 9 Aug 2015

We could create a new case:

case 'RAW':
                // Keep the date as absolute.
                if ($this->value && $this->value != JFactory::getDbo()->getNullDate())
                {
                    $this->value = $this->value->format('Y-m-d H:i:s', true, false);
                }

                break;

and change filter to "raw"
I guess It would be B/C as the filter does not exist yet.

avatar Bakual
Bakual - comment - 9 Aug 2015

You would also have to change the part where it is rendered. Currently it should be JHtml::Date($date, $format, false). You would have to use JHtml::Date($date, $format, null) to output it as it is stored.

avatar infograf768
infograf768 - comment - 9 Aug 2015

About the rendering, I was thinking of something like:
for components/com_contact/views/contact/tmpl/default_profile.php

+                       case "profile_dob":
+                           echo "<dd>" . JHtml::_('date', $profile->text, JText::_('DATE_FORMAT_LC4')) . "</dd>";
+                           break;
+

and in components/com_users/views/profile/tmpl/default_custom.php

+           <?php if ($field->type == 'Dob') : ?>
+               <?php $field->value = JHtml::_('date', $field->value, JText::_('DATE_FORMAT_LC4')); ?>
+           <?php endif; ?>
avatar infograf768
infograf768 - comment - 9 Aug 2015

BTW, I do confirm that using filter="server_utc" (i.e. no patch) displays a wrong date if the server is set to a UTC+ which is the case for Paris and Moscow for example.

avatar infograf768
infograf768 - comment - 9 Aug 2015

Added the new filter and date formatting for the display.

avatar infograf768
infograf768 - comment - 9 Aug 2015

forgot to update default_profile.php as it was behind staging. Trying to do now

avatar Bakual
Bakual - comment - 9 Aug 2015

Ah sorry, I see now what you meant. The real issue is only in the display part, as currently the date is displayed as a regular value instead of using the JHtml::date method.
I think I have a better idea how to solve it, based on your PR a bit. Please see #7666

avatar Bakual
Bakual - comment - 9 Aug 2015

On a sidenote: If you really want to have the date stored without any timezones applied, you can use filter="none" (or whatever you want actually) and it will not do anything with the value.

When showing the date, you still need to use JHtml::('date', $value, $format, null) or JHtml::('date', $value, $format, 'UTC') as I wrote above so you can apply proper formatting.

avatar infograf768 infograf768 - close - 10 Aug 2015
avatar infograf768
infograf768 - comment - 10 Aug 2015

Closing in favour of #7666

avatar infograf768 infograf768 - change - 10 Aug 2015
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2015-08-10 06:27:14
Closed_By infograf768
avatar infograf768 infograf768 - close - 10 Aug 2015
avatar infograf768 infograf768 - head_ref_deleted - 11 Aug 2015

Add a Comment

Login with GitHub to post a comment