Bug in functions.lib.php in dol_mktime function

Hi there, I encounter myself with a bug when creating a new task for a project on version 3.6 for windows on Chrome.

The error said:

[02-Sep-2014 13:43:16] PHP Fatal error: Uncaught exception ‘Exception’ with message ‘DateTime::__construct() expects parameter 2 to be DateTimeZone, null given’ in C:\dolibarr\www\dolibarr\htdocs\core\lib\functions.lib.php:1052
Stack trace:
#0 C:\dolibarr\www\dolibarr\htdocs\core\lib\functions.lib.php(1052): DateTime->__construct(’’, NULL)
#1 C:\dolibarr\www\dolibarr\htdocs\projet\tasks.php(86): dol_mktime(‘10’, ‘41’, 0, ‘09’, ‘02’, ‘2014’, ‘user’)
#2 {main}
thrown in C:\dolibarr\www\dolibarr\htdocs\core\lib\functions.lib.php on line 1052

After looking in the files I found that the function on line 1052 was missing an assignment after the try and catch statement.

I was using Chrome, and it seems that the Timezones that uses Chrome are invalid. Some when it enters the catch statement there is no assignment so $localtz is null at the time of new DateTime.

catch code:

catch(Exception $e)
{
dol_syslog("Warning dol_tz_string contains an invalid value ".$_SESSION[“dol_tz_string”], LOG_WARNING);
$default_timezone=@date_default_timezone_get();
// missing: $localtz = new DateTimeZone($default_timezone);
}

Same bug encountered, same fix.

Thanks to OP :happy:

Hi,

You have put it right TimeZone on the server?

On one hand the variable is not being initialize inside the catch. So that’s a real bug no matter what.

On the other hand, this problem occurred on chrome and not on IE. It seems to be also related with the browser language, and the way they parse timezones.

Dolibarr is not managing correctly the TZ strings use by chrome. That’s why it enters on the catch statement.