$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
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
)
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
)
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
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.
Labels |
Added:
?
|
Status | New | ⇒ | Information Required |
@bembelimen any comments on this?
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?
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
@irbian can you create a Pull Request (https://extensions.joomla.org/blog/item/how-to-contribute-to-joomla-through-github/)?
I could try, but I´m not sure yet the most correct way to solve it. Using setTimezone on the constructor?
@HLeithner can you please answer?
Category | ⇒ | com_config |
Labels |
Added:
J3 Issue
|
@irbian are you still seeing this as an issue?
Labels |
Added:
Information Required
|
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
Status | Information Required | ⇒ | New |
Labels |
Removed:
Information Required
|
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: ? |
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.
@Quy can you please have a Look?
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24196.