Skip to content

Commit

Permalink
Qual: Start to clean old code.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 21, 2014
1 parent 63bb09f commit 7fb0049
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
13 changes: 8 additions & 5 deletions htdocs/core/lib/date.lib.php
Expand Up @@ -75,15 +75,14 @@ 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)
*/
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');
Expand All @@ -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;
Expand All @@ -111,14 +112,15 @@ 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;
$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'; // For true result
}
else $tmp=dol_mktime(0,0,0,1,1,1970);
*/
}
$tz=round(($tmp<0?1:-1)*abs($tmp/3600));
return $tz;
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions htdocs/install/check.php
Expand Up @@ -73,12 +73,12 @@
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
{
Expand Down
9 changes: 0 additions & 9 deletions test/phpunit/DateLibTest.php
Expand Up @@ -313,15 +313,6 @@ public function testDolStringToTime()
$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";
Expand Down

0 comments on commit 7fb0049

Please sign in to comment.