No Code Attached Yet J3 Issue
avatar fgossart
fgossart
20 Jun 2018

Steps to reproduce the issue

the issue for programming components with filtering by datetime.
if your own component, or just try with content component.(administrator mode)
add in filter_articles.xml to try for example a filter based on creation date
field name="created" type="calendar" label="created date"
description="" size="22"
translateformat="true"
showtime="true" filter="user_utc"
onchange="this.form.submit();"

the in model articles.php in function populatestate add
$created = $this->getUserStateFromRequest($this->context . '.filter.created', 'filter_created', '');
$this->setState('filter.created', $created);

if you are not at GMT time, select a datetime, and every refresh it increases (two hours for me in Europe/paris)

Expected result

Actual result

System information (as much as possible)

Additional comments

avatar fgossart fgossart - open - 20 Jun 2018
avatar joomla-cms-bot joomla-cms-bot - labeled - 20 Jun 2018
avatar fgossart fgossart - change - 20 Jun 2018
The description was changed
avatar fgossart fgossart - edited - 20 Jun 2018
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 20 Jun 2018

Similar (closed) Issues: #20271 #14284 #12329 - are they different to your Issue, @fgossart?

avatar fgossart
fgossart - comment - 20 Jun 2018

No it's not the same issue. I'm using some datetimes field with no problem in forms.

it's just inside a listview when adding a datetime as a filter, because datetime form field is not attached to a database table, so not converted.
No native components are using this kind of filter so to reproduce issue, it's when creating or modifiing native component.

if you want to filter articles with creating datetime < filter_datetime you can reproduce this issue, adding code I put on the issue. Not necessary to modify filtering in the query, just when form is submit datetime content change.

De: "Franz Wohlkönig" notifications@github.com
À: "joomla/joomla-cms" joomla-cms@noreply.github.com
Cc: "Fabrice GOSSART" fabrice@gossart.fr, "Mention" mention@noreply.github.com
Envoyé: Mercredi 20 Juin 2018 13:47:37
Objet: Re: [joomla/joomla-cms] filtering with a datetime (backend) increase hours due to timezone (#20807)

Similar (closed) Issues: [ https://github.com/joomla/joomla-cms/issues/20271 | #20271 ] [ https://github.com/joomla/joomla-cms/issues/14284 | #14284 ] [ https://github.com/joomla/joomla-cms/issues/12329 | #12329 ] - are they different to your Issue, [ https://github.com/fgossart | @fgossart ] ?


You are receiving this because you were mentioned.
Reply to this email directly, [ https://github.com/joomla/joomla-cms/issues/20807#issuecomment-398721250 | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/ABGaKtIFdOwJ72fUtzR8uMMPsqw2ojqdks5t-jZZgaJpZM4Uu8Ty | mute the thread ] .

avatar schnuti
schnuti - comment - 20 Jun 2018

I guess a public method is missing that you have to call before setting the state.
For a form you have:

    // Convert a date to UTC based on the user timezone offset.
    case 'USER_UTC':
avatar fgossart
fgossart - comment - 20 Jun 2018

I have tried both values (server_utc and user_utc), same issue. I have debugged with Xdebug. Value is overrided when calendar field JHTML is called
I have no problem when refreshing a standard form with a datetime calendar field, only with filter .. I know it's very curious. Probably in populatestate function (model) override with post values

De: "Ove Eriksson" notifications@github.com
À: "joomla" joomla-cms@noreply.github.com
Cc: "Fabrice GOSSART" fabrice@gossart.fr, "Mention" mention@noreply.github.com
Envoyé: Mercredi 20 Juin 2018 14:13:08
Objet: Re: [joomla/joomla-cms] filtering with a datetime (backend) increase hours due to timezone (#20807)

I guess a public method is missing that you have to call before setting the state.
For a form you have:
// Convert a date to UTC based on the user timezone offset.
case 'USER_UTC':


You are receiving this because you were mentioned.
Reply to this email directly, [ https://github.com/joomla/joomla-cms/issues/20807#issuecomment-398727280 | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/ABGaKoNo78B54sdox2o4cQwkCgYdDJWaks5t-jxUgaJpZM4Uu8Ty | mute the thread ] .

avatar franz-wohlkoenig franz-wohlkoenig - change - 20 Jun 2018
Status New Discussion
avatar franz-wohlkoenig franz-wohlkoenig - change - 20 Jun 2018
Category com_content
avatar schnuti
schnuti - comment - 20 Jun 2018

Something like this probably, but I think it's a bit tricky. It's only an idea.

$created = $this->getUserStateFromRequest($this->context . '.filter.created', 'filter_created', '');
// Translate to UTC time  e.g. user time 15:02:30 -> utc+0  13:02:30 IF it's a new value
$created = $this->userUtcToUtc($created);
$this->setState('filter.created', $created);


`
avatar fgossart
fgossart - comment - 20 Jun 2018

:)
I have tried a conversion but the issue is crazy.
Even if you put another value, it's override... why ?
I try this
$created = $this ->getUserStateFromRequest( $this -> context . '.filter.created' , 'filter_created' , '' );
$created = "2018-01-01 10:00:00" ;
$this ->setState( 'filter.created' , $created );

It seems nonsense, but the shown value should be 2018-01-01 10:00:00 but no.. it keeps the previous value and adding 2 hours every time refresh
so I don't understand the use of of setState in the model, because even if I comment it (idem for other filter field)

So the issue is not in the populateState function, it' s because I don't understand how are stored the filters forms values. Populastate is dummy ?

De: "Ove Eriksson" notifications@github.com
À: "joomla" joomla-cms@noreply.github.com
Cc: "Fabrice GOSSART" fabrice@gossart.fr, "Mention" mention@noreply.github.com
Envoyé: Mercredi 20 Juin 2018 15:13:55
Objet: Re: [joomla/joomla-cms] filtering with a datetime (backend) increase hours due to timezone (#20807)

Something like this probably, but I think it's a bit tricky. It's only an idea.
$created = $this->getUserStateFromRequest($this->context . '.filter.created', 'filter_created', '');
// Translate to UTC time e.g. user time 15:02:30 -> utc+0 13:02:30 IF it's a new value
$created = $this->userUtcToUtc($created);
$this->setState('filter.created', $created);

`


You are receiving this because you were mentioned.
Reply to this email directly, [ https://github.com/joomla/joomla-cms/issues/20807#issuecomment-398743793 | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/ABGaKjVhxSr2LuRXBTgj6oszrC4lvOXHks5t-kqTgaJpZM4Uu8Ty | mute the thread ] .

avatar schnuti
schnuti - comment - 21 Jun 2018

I find the issue here is: How to convert a users UTC+/- x time to UTC+0. I can't find a public method for it but a lot of from UTC+0 to userUTC or to serverUTC.

The rest is a "How to" and would belong to another forum.

I doubt this is "The Way" to do it. We have to modify the stored form data replacing userUTC with UTC. I do this by changing the request. (You have to instantiate the Application (or Input) if you haven't.)

  $filters = $app->input->get('filter', array(), 'array');

  if (isset($filters['created_time']))
  {
    $created_time = $filters['created_time'];
    $filters['created_time'] = $this->dateUtc($created_time);
    $app->input->set('filter', $filters);
  }

  $created_time = $this->getUserStateFromRequest($this->context . '.filter.created_time',  
        'filter_created_time', '');
  $this->setState('filter.created_time', $created_time);

and a method for the test only. From JForm, with removed parameters

// Convert a date to UTC based on the user timezone offset.
public function dateUtc($value)
{
    if ((int) $value > 0)
    {
      $format   = \JText::_('DATE_FORMAT_FILTER_DATETIME');
      $date     = date_parse_from_format($format, $value);
      $value    = (int) $date['year'] . '-' . (int) $date['month'] . '-' . (int) $date['day'];

      $value .= ' ' . (int) $date['hour'] . ':' . (int) $date['minute'] . ':' . (int) $date['second'];

      // Get the user timezone setting defaulting to the server timezone setting.
      $offset = \JFactory::getUser()->getTimezone();

      // Return a MySQL formatted datetime string in UTC.
      try
      {
        return \JFactory::getDate($value, $offset)->toSql();
      }
      catch (\Exception $e)
      {
        \JFactory::getApplication()->enqueueMessage(
        \JText::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', \JText::_((string) $element['label'])), 'warning');

        return '';
      }
  }
  else
  {
    return '';
  }
}

PS. Keep an eye on getStoreId ($id = '') and getStoreId ($id = '') if the db-query do not run as expected.

avatar schnuti
schnuti - comment - 21 Jun 2018

Be aware: I tried to add a calendar field to the filters in J 4.0 but that failed completely.

avatar fgossart
fgossart - comment - 21 Jun 2018

I 'm still on Joomla 3.8X
Have you tried te reproduce the error?

De: "Ove Eriksson" notifications@github.com
À: "joomla" joomla-cms@noreply.github.com
Cc: "Fabrice GOSSART" fabrice@gossart.fr, "Mention" mention@noreply.github.com
Envoyé: Jeudi 21 Juin 2018 10:16:07
Objet: Re: [joomla/joomla-cms] filtering with a datetime (backend) increase hours due to timezone (#20807)

Be aware: I tried to add a calendar field to the filters in J 4.0 but that failed completely.


You are receiving this because you were mentioned.
Reply to this email directly, [ https://github.com/joomla/joomla-cms/issues/20807#issuecomment-399016341 | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/ABGaKnljUgkP5gudESeZEJEBO1tHeFXKks5t-1ZHgaJpZM4Uu8Ty | mute the thread ] .

avatar schnuti
schnuti - comment - 21 Jun 2018

It's resolved with the code above. (my field name is created_time)

avatar fgossart
fgossart - comment - 21 Jun 2018

okay, I will try and use it... but is it an issue ? and a workaround?

De: "Ove Eriksson" notifications@github.com
À: "joomla" joomla-cms@noreply.github.com
Cc: "Fabrice GOSSART" fabrice@gossart.fr, "Mention" mention@noreply.github.com
Envoyé: Jeudi 21 Juin 2018 16:19:26
Objet: Re: [joomla/joomla-cms] filtering with a datetime (backend) increase hours due to timezone (#20807)

It's resolved with the code above. (my field name is created_time)


You are receiving this because you were mentioned.
Reply to this email directly, [ https://github.com/joomla/joomla-cms/issues/20807#issuecomment-399120042 | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/ABGaKoa3-TeNEV5D37Z5Zy2gpjz_chjLks5t-6tugaJpZM4Uu8Ty | mute the thread ] .

avatar schnuti
schnuti - comment - 21 Jun 2018

As I wrote, the issue would be to ask for a method to handle the userUTC to UTC translation. It's not a workaround only a matter of taste where the request should be updated.

avatar brianteeman brianteeman - change - 22 Jun 2018
Labels Added: J3 Issue
avatar brianteeman brianteeman - labeled - 22 Jun 2018
avatar jwaisner jwaisner - change - 13 Mar 2020
Status Discussion Confirmed
avatar brianteeman
brianteeman - comment - 23 Aug 2022

Thank you for raising this issue.

Joomla 3 is now in security only mode with no further bug fixes or new features.

As this issue doesn't relate to Joomla 4 it will now been closed.

If we are mistaken and this does apply to Joomla 4 please open a new issue (and reference this one if you wish) with updated details for testing in Joomla 4.
cc @zero-24

avatar zero-24 zero-24 - change - 23 Aug 2022
Status Confirmed Closed
Closed_Date 0000-00-00 00:00:00 2022-08-23 13:46:09
Closed_By zero-24
Labels Added: No Code Attached Yet
Removed: ?
avatar zero-24 zero-24 - close - 23 Aug 2022

Add a Comment

Login with GitHub to post a comment