Dolibarr arrojaba el siguiente error al crear una nueva tarea dentro de un proyecto.
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:1057 Stack trace: #0 C:\dolibarr\www\dolibarr\htdocs\core\lib\functions.lib.php(1057): DateTime->__construct('', NULL) #1 C:\dolibarr\www\dolibarr\htdocs\projet\tasks.php(86): dol_mktime('17', '09', 0, '10', '30', '2014', 'user') #2 {main} thrown in C:\dolibarr\www\dolibarr\htdocs\core\lib\functions.lib.php on line 1057
Se solucionó agregando una línea en functions.lib.php.
Les dejo una captura donde verán qué línea se agrega en el catch (marcada con rojo)
Cómo Solucionar Fatal Error por TimeZone (Por nueva tarea)
-
- Novato
- Mensajes: 4
- Registrado: Lun, 27/10/2014, 19:50
-
- Novato
- Mensajes: 4
- Registrado: Lun, 27/10/2014, 19:50
Disculpen no me di cuenta de que no anduvo la subida de la imagen.
El archivo es core/lib/functions.lib.php, y el unico cambio es la linea
$localtz = new DateTimeZone($default_timezone);
Agregada como última linea del único catch que hay en la función.
Sin esa linea, cuando se entra a ese catch la variable $localtz queda en null, y mas abajo hace
$dt = new DateTime(null,$localtz);
y ahí es donde tira el error que veíamos.
function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
{
global $conf;
//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
// Clean parameters
if ($hour == -1 || empty($hour)) $hour=0;
if ($minute == -1 || empty($minute)) $minute=0;
if ($second == -1 || empty($second)) $second=0;
// Check parameters
if ($check)
{
if (! $month || ! $day) return '';
if ($day > 31) return '';
if ($month > 12) return '';
if ($hour < 0 || $hour > 24) return '';
if ($minute< 0 || $minute > 60) return '';
if ($second< 0 || $second > 60) return '';
}
if (method_exists('DateTime','getTimestamp'))
{
if (empty($gm) || $gm === 'server')
{
$default_timezone=@date_default_timezone_get();
$localtz = new DateTimeZone($default_timezone);
}
else if ($gm === 'user')
{
// We use dol_tz_string first because it contains dst.
$default_timezone=(empty($_SESSION["dol_tz_string"])?@date_default_timezone_get():$_SESSION["dol_tz_string"]);
try {
$localtz = new DateTimeZone($default_timezone);
}
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();
$localtz = new DateTimeZone($default_timezone);
}
}
else $localtz = new DateTimeZone('UTC');
$dt = new DateTime(null,$localtz);
$dt->setDate($year,$month,$day);
$dt->setTime((int) $hour, (int) $minute, (int) $second);
$date=$dt->getTimestamp(); // should include daylight saving time
}
else
{
dol_print_error('','PHP version must be 5.3+');
/*
$usealternatemethod=false;
if ($year <= 1970) $usealternatemethod=true; // <= 1970
if ($year >= 2038) $usealternatemethod=true; // >= 2038
if ($usealternatemethod || $gm) // Si time gm, seule adodb peut convertir
{
$date=adodb_mktime($hour,$minute,$second,$month,$day,$year,0,$gm);
}
else
{
$date=mktime($hour,$minute,$second,$month,$day,$year);
}*/
}
return $date;
}
El archivo es core/lib/functions.lib.php, y el unico cambio es la linea
$localtz = new DateTimeZone($default_timezone);
Agregada como última linea del único catch que hay en la función.
Sin esa linea, cuando se entra a ese catch la variable $localtz queda en null, y mas abajo hace
$dt = new DateTime(null,$localtz);
y ahí es donde tira el error que veíamos.
function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
{
global $conf;
//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
// Clean parameters
if ($hour == -1 || empty($hour)) $hour=0;
if ($minute == -1 || empty($minute)) $minute=0;
if ($second == -1 || empty($second)) $second=0;
// Check parameters
if ($check)
{
if (! $month || ! $day) return '';
if ($day > 31) return '';
if ($month > 12) return '';
if ($hour < 0 || $hour > 24) return '';
if ($minute< 0 || $minute > 60) return '';
if ($second< 0 || $second > 60) return '';
}
if (method_exists('DateTime','getTimestamp'))
{
if (empty($gm) || $gm === 'server')
{
$default_timezone=@date_default_timezone_get();
$localtz = new DateTimeZone($default_timezone);
}
else if ($gm === 'user')
{
// We use dol_tz_string first because it contains dst.
$default_timezone=(empty($_SESSION["dol_tz_string"])?@date_default_timezone_get():$_SESSION["dol_tz_string"]);
try {
$localtz = new DateTimeZone($default_timezone);
}
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();
$localtz = new DateTimeZone($default_timezone);
}
}
else $localtz = new DateTimeZone('UTC');
$dt = new DateTime(null,$localtz);
$dt->setDate($year,$month,$day);
$dt->setTime((int) $hour, (int) $minute, (int) $second);
$date=$dt->getTimestamp(); // should include daylight saving time
}
else
{
dol_print_error('','PHP version must be 5.3+');
/*
$usealternatemethod=false;
if ($year <= 1970) $usealternatemethod=true; // <= 1970
if ($year >= 2038) $usealternatemethod=true; // >= 2038
if ($usealternatemethod || $gm) // Si time gm, seule adodb peut convertir
{
$date=adodb_mktime($hour,$minute,$second,$month,$day,$year,0,$gm);
}
else
{
$date=mktime($hour,$minute,$second,$month,$day,$year);
}*/
}
return $date;
}