Fix with PHP 5.2

This commit is contained in:
Laurent Destailleur 2012-06-05 12:54:34 +02:00
parent 5ce0fe1405
commit 31560e19df

View File

@ -83,7 +83,7 @@ function getServerTimeZoneString()
function getServerTimeZoneInt($refgmtdate='now')
{
global $conf;
if (class_exists('DateTime') && ! empty($conf->global->MAIN_NEW_DATE))
if (method_exists('DateTimeZone','getOffset') && ! empty($conf->global->MAIN_NEW_DATE))
{
// Method 1 (include daylight)
$gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref=dol_print_date($gmtnow,'%m'); $dayref=dol_print_date($gmtnow,'%d');
@ -100,21 +100,23 @@ function getServerTimeZoneInt($refgmtdate='now')
// Method 2 (does not include daylight, not supported by adodb)
if ($refgmtdate == 'now')
{
if (ini_get("date.timezone")=='UTC') return 0;
// We don't know server timezone string, so we don't know location, so we can't guess daylight. We assume we use same than client. Fix is to use MAIN_NEW_DATE.
$gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref=dol_print_date($gmtnow,'%m'); $dayref=dol_print_date($gmtnow,'%d');
if (dol_stringtotime($_SESSION['dol_dst_first']) <= $gmtnow && $gmtnow < dol_stringtotime($_SESSION['dol_dst_second'])) $daylight=1;
else $daylight=0;
$tmp=dol_mktime(0,0,0,$monthref,$dayref,$yearref,false,0)-dol_mktime(0,0,0,$monthref,$dayref,$yearref,true,0)-($daylight*3600);
return 'unknown';
return 'unknown'; // For true result
}
elseif ($refgmtdate == 'summer')
{
if (ini_get("date.timezone")=='UTC') return 0;
// We don't know server timezone string, so we don't know location, so we can't guess daylight. We assume we use same than client. Fix is to use MAIN_NEW_DATE.
$gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref='08'; $dayref='01';
if (dol_stringtotime($_SESSION['dol_dst_first']) <= dol_stringtotime($yearref.'-'.$monthref.'-'.$dayref) && dol_stringtotime($yearref.'-'.$monthref.'-'.$dayref) < dol_stringtotime($_SESSION['dol_dst_second'])) $daylight=1;
else $daylight=0;
$tmp=dol_mktime(0,0,0,$monthref,$dayref,$yearref,false,0)-dol_mktime(0,0,0,$monthref,$dayref,$yearref,true,0)-($daylight*3600);
return 'unknown';
return 'unknown'; // For true result
}
else $tmp=dol_mktime(0,0,0,1,1,1970);
}