2
0
forked from Wavyzz/dolibarr

Fix: daylight depends also on year (not only month and day)

This commit is contained in:
Laurent Destailleur
2012-05-15 00:48:59 +02:00
parent bd26c9e465
commit e7138bce4e
2 changed files with 24 additions and 9 deletions

View File

@@ -160,11 +160,12 @@ print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("CurrentTimeZone").'</t
$a=getServerTimeZoneInt('now');
$b=getServerTimeZoneInt('winter');
$c=getServerTimeZoneInt('summer');
$daylight=round($b-$c);
$daylight=(is_numeric($c) && is_numeric($b))?round($c-$b):'unknown';
//print $a." ".$b." ".$c." ".$daylight;
$val=($a>=0?'+':'').$a;
$val.=' ('.($a>=0?'+':'').($a*3600).')';
$val.=' ('.($a==='unknown'?'unknown':($a>=0?'+':'').($a*3600)).')';
$val.=' &nbsp; &nbsp; &nbsp; '.getServerTimeZoneString().' '.($b>=0?'+':'').$b.' ('.($b>=0?'+':'').($b*3600).')';
$val.=' &nbsp; &nbsp; &nbsp; '.$langs->trans("DaylingSavingTime").': '.yn($daylight);
$val.=' &nbsp; &nbsp; &nbsp; '.$langs->trans("DaylingSavingTime").': '.($daylight==='unknown'?'unknown':yn($daylight));
print $form->textwithtooltip($val,$txt,2,1,img_info(''));
print '</td></tr>'."\n"; // value defined in http://fr3.php.net/manual/en/timezones.europe.php
$var=!$var;

View File

@@ -86,25 +86,39 @@ function getServerTimeZoneInt($refgmtdate='now')
if (class_exists('DateTime') && ! 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');
if ($refgmtdate == 'now') $newrefgmtdate=$yearref.'-'.$monthref.'-'.$dayref;
elseif ($refgmtdate == 'summer') $newrefgmtdate=$yearref.'-05-15';
else $newrefgmtdate=$yearref.'-01-01';
$localtz = new DateTimeZone(getServerTimeZoneString());
$localdt = new DateTime($refgmtdate, $localtz);
$localdt = new DateTime($newrefgmtdate, $localtz);
$tmp=-1*$localtz->getOffset($localdt);
//print $refgmtdate.'='.$tmp;
}
else
{
// Method 2 (does not include daylight, not supported by adodb)
if ($refgmtdate == 'now')
{
$gmtnow=dol_now('gmt');
$monthnow=dol_print_date($gmtnow,'%m'); $daynow=dol_print_date($gmtnow,'%d');
// 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,$monthnow,$daynow,1970,false,0)-dol_mktime(0,0,0,$monthnow,$daynow,1970,true,0)-($daylight*3600);
$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';
}
elseif ($refgmtdate == 'summer')
{
// 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';
}
else if ($refgmtdate == 'summer') $tmp=-1; // TODO
else $tmp=dol_mktime(0,0,0,1,1,1970);
}
$tz=($tmp<0?1:-1)*abs($tmp/3600);
$tz=round(($tmp<0?1:-1)*abs($tmp/3600));
return $tz;
}