No Code Attached Yet J3 Issue
avatar irbian
irbian
15 Mar 2019

Steps to reproduce the issue

         $config = JFactory::getConfig();
         $offset = $config->get('offset');
         $tz = new DateTimeZone($offset);
         $date = JFactory::getDate($timestamp, $tz); 
         //            $date->setTimezone($tz);
         print_r($date);
         $date->toSql(true);

Both php config and Joomla config, with timezone set to Atlantic/Canary

Expected result

Joomla\CMS\Date\Date Object
(
    [tz:protected] => DateTimeZone Object
        (
            [timezone_type] => 3
            [timezone] => Atlantic/Canary
        )

    [date] => 2018-10-22 23:59:00.000000
    [timezone_type] => 3
    [timezone] => Atlantic/Canary
)

Actual result

Joomla\CMS\Date\Date Object
(
    [tz:protected] => DateTimeZone Object
        (
            [timezone_type] => 3
            [timezone] => Atlantic/Canary
        )

    [date] => 2018-10-22 22:59:00.000000
    [timezone_type] => 1
    [timezone] => +00:00
)

System information (as much as possible)

In this line we are setting the $tz property, but not the internal $tz. ¿Wouldn´t be that necessary? https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Date/Date.php#L118

¿Or maybe is something to control on the format method, here? https://github.com/joomla/joomla-cms/blame/staging/libraries/src/Date/Date.php#L293

Additional comments

Actually, if I recall correctly, the problem is not with the timezone, but with the DST, because you need the timezone_type properly set so the date format takes it into account

If I uncomment the commented line in my code, it works.

avatar irbian irbian - open - 15 Mar 2019
avatar joomla-cms-bot joomla-cms-bot - change - 15 Mar 2019
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 15 Mar 2019
avatar irbian irbian - change - 15 Mar 2019
The description was changed
avatar irbian irbian - edited - 15 Mar 2019
avatar irbian irbian - change - 15 Mar 2019
The description was changed
avatar irbian irbian - edited - 15 Mar 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 16 Mar 2019
Status New Information Required
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 16 Mar 2019

@Quy can you please have a Look?


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

avatar HLeithner
HLeithner - comment - 18 Mar 2019

@bembelimen any comments on this?

avatar mbabker
mbabker - comment - 18 Mar 2019

When the Date class is instantiated, it standardizes dates to UTC and the user's selected timezone stored in the Joomla\CMS\Date\Date::$tz property with UTC being pushed up into DateTime::$timezone. See the constructor for details.

What practical issues are you experiencing with the standardized UTC timezone?

avatar irbian
irbian - comment - 18 Mar 2019

It's simple, if I use the format method (https://github.com/joomla/joomla-cms/blame/staging/libraries/src/Date/Date.php#L281) with local a true, it doesn´t show the local time taking into account the DST, because it never execute a setTimezone

Actually, is even more fun, because of https://github.com/joomla/joomla-cms/blame/staging/libraries/src/Date/Date.php#L327, if I do:

format(false) // works
format(true) // works

But if I don´t do it

// format(false) //
format(true) // don´t work

Again, because the inner object doesn´t have its timezone properly set

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 20 Mar 2019
avatar irbian
irbian - comment - 20 Mar 2019

I could try, but I´m not sure yet the most correct way to solve it. Using setTimezone on the constructor?

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 22 Mar 2019

@HLeithner can you please answer?

avatar franz-wohlkoenig franz-wohlkoenig - change - 22 Mar 2019
Category com_config
avatar HLeithner
HLeithner - comment - 22 Mar 2019

I think @mbabker has much more knowledge about this as me, I also experienced problems with jdate and timezones... but didn't debugged it... changing something in jdate could lead to unexpected behavior for existing installations...

avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Apr 2019
Labels Added: J3 Issue
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 4 Apr 2019
avatar jwaisner
jwaisner - comment - 11 Mar 2020

@irbian are you still seeing this as an issue?


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

avatar Quy Quy - change - 11 Mar 2020
Labels Added: Information Required
avatar Quy Quy - labeled - 11 Mar 2020
avatar irbian
irbian - comment - 13 Mar 2020

Interesting enough, I haven´t found this issue in a lot of places. One would be https://github.com/joomla/joomla-cms/blame/staging/administrator/components/com_categories/models/category.php where the setTimezone is already called and also on https://github.com/joomla/joomla-cms/blame/staging/administrator/components/com_tags/models/tag.php

I see at least three problems. How big of a problem they are is beyond me

  • One. JFactory::getDate($timestamp, $tz), won´t set the internal date object timezone that some methods as Date::format use
  • Two. format is not a function, but a procedure, because it modifies the internal date object timezone
  • Three $date->toSql(true) won´t work unless you have called explicitly before, the method setTimezone
avatar jwaisner jwaisner - change - 15 Mar 2020
Status Information Required New
avatar Quy Quy - change - 6 May 2020
Labels Removed: Information Required
avatar Quy Quy - unlabeled - 6 May 2020
avatar joomdonation joomdonation - change - 12 Nov 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-11-12 09:15:14
Closed_By joomdonation
Labels Added: No Code Attached Yet
Removed: ?
avatar joomdonation joomdonation - close - 12 Nov 2022
avatar joomdonation
joomdonation - comment - 12 Nov 2022

Look like the issue was solved elsewhere. I just tried on latest Joomla 4 and could not re-procedure the issue anymore. The date object has timezone set to the passed timezone (I remember there was a PR dealing with this issue sometime ago).

With that said, I'm closing this issue. Feel free to re-open if the issue is still valid.

Add a Comment

Login with GitHub to post a comment