Qual: Start to clean old code.

This commit is contained in:
Laurent Destailleur 2014-03-21 15:02:27 +01:00
parent 63bb09fbdf
commit 7fb004903e
4 changed files with 15 additions and 19 deletions

View File

@ -75,7 +75,6 @@ function getServerTimeZoneString()
/**
* Return server timezone int.
* If $conf->global->MAIN_OLD_DATE is set or PHP too old, we use old behaviour: All convertions does not take care of dayling saving time.
*
* @param string $refgmtdate Reference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer')
* @return int An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer)
@ -83,7 +82,7 @@ function getServerTimeZoneString()
function getServerTimeZoneInt($refgmtdate='now')
{
global $conf;
if (method_exists('DateTimeZone','getOffset') && empty($conf->global->MAIN_OLD_DATE))
if (method_exists('DateTimeZone','getOffset'))
{
// 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');
@ -97,11 +96,13 @@ function getServerTimeZoneInt($refgmtdate='now')
}
else
{
dol_print_error('','PHP version must be 5.2+');
/*
// 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 new PHP with not MAIN_OLD_DATE.
// 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 but this may be a bug.
$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;
@ -111,7 +112,7 @@ function getServerTimeZoneInt($refgmtdate='now')
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 new PHP with not MAIN_OLD_DATE.
// 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 but this may be a bug.
$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;
@ -119,6 +120,7 @@ function getServerTimeZoneInt($refgmtdate='now')
return 'unknown'; // For true result
}
else $tmp=dol_mktime(0,0,0,1,1,1970);
*/
}
$tz=round(($tmp<0?1:-1)*abs($tmp/3600));
return $tz;
@ -146,7 +148,7 @@ function getParentCompanyTimeZoneString()
function getParentCompanyTimeZoneInt($refgmtdate='now')
{
global $conf;
if (class_exists('DateTime') && empty($conf->global->MAIN_OLD_DATE))
if (class_exists('DateTime'))
{
// Method 1 (include daylight)
$localtz = new DateTimeZone(getParentCompanyTimeZoneString());
@ -155,6 +157,7 @@ function getParentCompanyTimeZoneInt($refgmtdate='now')
}
else
{
dol_print_error('','PHP version must be 5.2+');
// Method 2 (does not include daylight)
$tmp=dol_mktime(0,0,0,1,1,1970);
}

View File

@ -1023,7 +1023,7 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
if ($second< 0 || $second > 60) return '';
}
if (method_exists('DateTime','getTimestamp') && empty($conf->global->MAIN_OLD_DATE))
if (method_exists('DateTime','getTimestamp'))
{
if (empty($gm)) $localtz = new DateTimeZone(date_default_timezone_get());
else $localtz = new DateTimeZone('UTC');
@ -1034,6 +1034,8 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
}
else
{
dol_print_error('','PHP version must be 5.2+');
/*
$usealternatemethod=false;
if ($year <= 1970) $usealternatemethod=true; // <= 1970
if ($year >= 2038) $usealternatemethod=true; // >= 2038
@ -1045,7 +1047,7 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1)
else
{
$date=mktime($hour,$minute,$second,$month,$day,$year);
}
}*/
}
return $date;
}

View File

@ -73,12 +73,12 @@ if (! empty($useragent))
if (versioncompare(versionphparray(),array(4,3,10)) < 0) // Minimum to use (error if lower)
{
print '<img src="../theme/eldy/img/error.png" alt="Error"> '.$langs->trans("ErrorPHPVersionTooLow",'4.3.10');
$checksok=0;
$checksok=0; // 0=error, 1=warning
}
else if (versioncompare(versionphparray(),array(5,2,0)) < 0) // Minimum supported (warning if lower)
else if (versioncompare(versionphparray(),array(5,2,0)) < 0) // Minimum supported (error if lower)
{
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("WarningPHPVersionTooLow",'5.2.0');
$checksok=1;
$checksok=0; // 0=error, 1=warning
}
else
{

View File

@ -313,15 +313,6 @@ class DateLibTest extends PHPUnit_Framework_TestCase
$langs=$this->savlangs;
$db=$this->savdb;
$conf->global->MAIN_OLD_DATE=1;
$stime='19700102';
$result=dol_stringtotime($stime);
print __METHOD__." result=".$result."\n";
$this->assertEquals(86400,$result);
$conf->global->MAIN_OLD_DATE=0;
$stime='19700102';
$result=dol_stringtotime($stime);
print __METHOD__." result=".$result."\n";