J4 Issue ? ? ?
avatar OctavianC
OctavianC
3 Feb 2021

Steps to reproduce the issue

These are the instructions for 4.0:

  • Go to System > Site Templates
  • Select Cassiopeia Details and Files
  • Press New File from the toolbar
  • From the left side select the html/mod_menu folder
  • Set File Name to exactly this: index-20210203-135009
  • Set File Type to .php
  • Press Create

This is a code snippet that showcases the issue:

$format = 'Y-m-d';
$value = '2021-02-03';
$validDate = JFactory::getDate()->createFromFormat($format, $value);
echo $validDate->format('d.m.Y');

Expected result

File created. success message and the newly created file being edited in the view.

The code snippet above should show 03.02.2021

Actual result

Error shows up DateTime::setTimezone(): Argument #1 ($timezone) must be of type DateTimeZone, null given in both cases.

System information (as much as possible)

PHP 8.0.1

Additional comments

The PHP changelog notes this:
Fixed bug #60302 (DateTime::createFromFormat should new static(), not new self()).

  • On PHP < 8, createFromFormat returns a DateTime object.
  • On PHP 8+, createFromFormat returns the extending class, in this case \Joomla\CMS\Date\Date

Perhaps changing this call https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Date/Date.php#L339-L342

if ($local == false)
{
	parent::setTimezone($this->tz);
}

To something like:

if ($local == false && $this->tz !== null)
{
	parent::setTimezone($this->tz);
}

Might fix this without causing other issues.

avatar OctavianC OctavianC - open - 3 Feb 2021
avatar joomla-cms-bot joomla-cms-bot - change - 3 Feb 2021
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 3 Feb 2021
avatar chmst chmst - change - 3 Feb 2021
Labels Added: J4 Issue ?
avatar chmst chmst - labeled - 3 Feb 2021
avatar chmst chmst - labeled - 3 Feb 2021
avatar chmst chmst - change - 3 Feb 2021
Labels Added: ?
avatar chmst chmst - labeled - 3 Feb 2021
avatar breebee
breebee - comment - 5 Feb 2021

I resolved this issue with the following on /libraries/src/Date/Date.php line 341

  • parent::setTimezone($this->tz);
  • parent::setTimezone(new \DateTimeZone('UTC'));
avatar OctavianC
OctavianC - comment - 5 Feb 2021

Yes, but from my understanding it's not meant to set it to UTC - it's meant to temporarily set it to UTC if $local is false and then revert to whatever timezone it was in the first place. Which should be stored in $this->tz, but I'm not sure why the returned class from createFromFormat() doesn't have $this->tz set. It seems that even though it returns a JDate object, it doesn't call __construct()

avatar chmst chmst - change - 20 Feb 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-02-20 19:53:04
Closed_By chmst
Labels Added: ?
Removed: ?
avatar chmst chmst - close - 20 Feb 2021
avatar chmst
chmst - comment - 20 Feb 2021

Cloing as we have a PR

Add a Comment

Login with GitHub to post a comment