mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-08 00:52:01 +01:00
Fix: daylight depends also on year (not only month and day)
This commit is contained in:
@@ -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.=' '.getServerTimeZoneString().' '.($b>=0?'+':'').$b.' ('.($b>=0?'+':'').($b*3600).')';
|
||||
$val.=' '.$langs->trans("DaylingSavingTime").': '.yn($daylight);
|
||||
$val.=' '.$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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user