diff --git a/htdocs/admin/system/dolibarr.php b/htdocs/admin/system/dolibarr.php index c357d0148d4e7b3d5e108f041443ab7cc52d5f03..1dfe1eb03e703c1cc4731d788d9698601239325b 100644 --- a/htdocs/admin/system/dolibarr.php +++ b/htdocs/admin/system/dolibarr.php @@ -157,10 +157,15 @@ $txt =$langs->trans("OSTZ").' (variable system TZ): '.($_ENV["TZ"]?$_ENV["TZ"]:$ $txt.=$langs->trans("PHPTZ").' (php.ini date.timezone): '.(ini_get("date.timezone")?ini_get("date.timezone"):$langs->trans("NotDefined")).''."\n"; // date.timezone must be in valued defined in http://fr3.php.net/manual/en/timezones.europe.php $var=!$var; print '<tr '.$bc[$var].'><td width="300">'.$langs->trans("CurrentTimeZone").'</td><td>'; // Timezone server PHP -$a=getServerTimeZoneString(); -$a.=' '.(getServerTimeZoneInt()>=0?'+':'').getServerTimeZoneInt(); -$a.=' ('.(getServerTimeZoneInt()>=0?'+':'').(getServerTimeZoneInt()*3600).')'; -print $form->textwithtooltip($a,$txt,2,1,img_info('')); +$a=getServerTimeZoneInt('now'); +$b=getServerTimeZoneInt('winter'); +$c=getServerTimeZoneInt('summer'); +$daylight=round($b-$c); +$val=($a>=0?'+':'').$a; +$val.=' ('.($a>=0?'+':'').($a*3600).')'; +$val.=' '.getServerTimeZoneString().' '.($b>=0?'+':'').$b.' ('.($b>=0?'+':'').($b*3600).')'; +$val.=' '.$langs->trans("DaylingSavingTime").': '.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; print '<tr '.$bc[$var].'><td width="300"> => '.$langs->trans("CurrentHour").'</td><td>'.dol_print_date(dol_now(),'dayhour','tzserver').'</td></tr>'."\n"; diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 7e741918d7277341ab995776f1738f368bdf403d..f7be31e1565d6a5cda0893e30a95a3985665790e 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -77,7 +77,7 @@ function getServerTimeZoneString() * Return server timezone int. * If $conf->global->MAIN_NEW_DATE is set, we use new behaviour: All convertions take care of dayling saving time. * - * @param string $refgmtdate Reference date for timezone (timezone differs on winter and summer) + * @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') @@ -92,8 +92,17 @@ function getServerTimeZoneInt($refgmtdate='now') } else { - // Method 2 (does not include daylight) - $tmp=dol_mktime(0,0,0,1,1,1970); + // 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'); + 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); + } + 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); return $tz; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b5efd93bf6e81ee3ea2edd628263b3de2fd876e4..44051f7e14e9f81e358c641cb727c48ddfa8c97b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1007,7 +1007,7 @@ function dol_now($mode='gmt') else if ($mode == 'tzserver') // Time for now with PHP server timezone added { require_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'); - $tzsecond=getServerTimeZoneInt(); // Contains tz+dayling saving time + $tzsecond=getServerTimeZoneInt('now'); // Contains tz+dayling saving time $ret=dol_now('gmt')+($tzsecond*3600); } /*else if ($mode == 'tzref') // Time for now with parent company timezone is added diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 45a683afbc2b4d3487f07f5f6121d3bcd18ee1b4..93fa494623c980de2459733fd45febf682bb2e73 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -140,8 +140,13 @@ function dol_print_object_info($object) $langs->load("other"); $langs->load("admin"); - $deltadateforuser=((int) $_SESSION['dol_tz'] + (int) $_SESSION['dol_dst']); + include_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'); + + $deltadateforserver=getServerTimeZoneInt('now'); + $deltadateforclient=((int) $_SESSION['dol_tz'] + (int) $_SESSION['dol_dst']); //$deltadateforcompany=((int) $_SESSION['dol_tz'] + (int) $_SESSION['dol_dst']); + $deltadateforuser=round($deltadateforclient-$deltadateforserver); + //print "x".$deltadateforserver." - ".$deltadateforclient." - ".$deltadateforuser; // Import key if (isset($object->import_key)) @@ -167,8 +172,8 @@ function dol_print_object_info($object) // Date creation if (isset($object->date_creation)) { - print $langs->trans("DateCreation")." : " . dol_print_date($object->date_creation,"dayhourtext"); - if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_creation+($deltadateforuser*3600),"dayhourtext").' '.$langs->trans("ClientHour"); + print $langs->trans("DateCreation")." : " . dol_print_date($object->date_creation,"dayhour"); + if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_creation+($deltadateforuser*3600),"dayhour").' '.$langs->trans("ClientHour"); print '<br>'; } @@ -192,8 +197,8 @@ function dol_print_object_info($object) // Date change if (isset($object->date_modification)) { - print $langs->trans("DateLastModification")." : " . dol_print_date($object->date_modification,"dayhourtext"); - if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_modification+($deltadateforuser*3600),"dayhourtext").' '.$langs->trans("ClientHour"); + print $langs->trans("DateLastModification")." : " . dol_print_date($object->date_modification,"dayhour"); + if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_modification+($deltadateforuser*3600),"dayhour").' '.$langs->trans("ClientHour"); print '<br>'; } @@ -217,8 +222,8 @@ function dol_print_object_info($object) // Date validation if (isset($object->date_validation)) { - print $langs->trans("DateValidation")." : " . dol_print_date($object->date_validation,"dayhourtext"); - if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_validation+($deltadateforuser*3600),"dayhourtext").' '.$langs->trans("ClientHour"); + print $langs->trans("DateValidation")." : " . dol_print_date($object->date_validation,"dayhour"); + if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_validation+($deltadateforuser*3600),"dayhour").' '.$langs->trans("ClientHour"); print '<br>'; } @@ -242,8 +247,8 @@ function dol_print_object_info($object) // Date approve if (isset($object->date_approve)) { - print $langs->trans("DateApprove")." : " . dol_print_date($object->date_approve,"dayhourtext"); - if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_approve+($deltadateforuser*3600),"dayhourtext").' '.$langs->trans("ClientHour"); + print $langs->trans("DateApprove")." : " . dol_print_date($object->date_approve,"dayhour"); + if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_approve+($deltadateforuser*3600),"dayhour").' '.$langs->trans("ClientHour"); print '<br>'; } @@ -267,8 +272,8 @@ function dol_print_object_info($object) // Date close if (isset($object->date_cloture)) { - print $langs->trans("DateClosing")." : " . dol_print_date($object->date_cloture,"dayhourtext"); - if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_cloture+($deltadateforuser*3600),"dayhourtext").' '.$langs->trans("ClientHour"); + print $langs->trans("DateClosing")." : " . dol_print_date($object->date_cloture,"dayhour"); + if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_cloture+($deltadateforuser*3600),"dayhour").' '.$langs->trans("ClientHour"); print '<br>'; } @@ -292,16 +297,16 @@ function dol_print_object_info($object) // Date conciliate if (isset($object->date_rappro)) { - print $langs->trans("DateConciliating")." : " . dol_print_date($object->date_rappro,"dayhourtext"); - if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_rappro+($deltadateforuser*3600),"dayhourtext").' '.$langs->trans("ClientHour"); + print $langs->trans("DateConciliating")." : " . dol_print_date($object->date_rappro,"dayhour"); + if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_rappro+($deltadateforuser*3600),"dayhour").' '.$langs->trans("ClientHour"); print '<br>'; } // Date send if (isset($object->date_envoi)) { - print $langs->trans("DateLastSend")." : " . dol_print_date($object->date_envoi,"dayhourtext"); - if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_envoi+($deltadateforuser*3600),"dayhourtext").' '.$langs->trans("ClientHour"); + print $langs->trans("DateLastSend")." : " . dol_print_date($object->date_envoi,"dayhour"); + if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' / '.dol_print_date($object->date_envoi+($deltadateforuser*3600),"dayhour").' '.$langs->trans("ClientHour"); print '<br>'; } } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 48b1c14a9983895cc690079e053d434adab2a25d..0fa4d7677de191910b9d72f6f147a483e86fea49 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -107,7 +107,7 @@ OSTZ=Time Zone OS server PHPTZ=Time Zone PHP server PHPServerOffsetWithGreenwich=PHP server offset width Greenwich (seconds) ClientOffsetWithGreenwich=Client/Browser offset width Greenwich (seconds) -DaylingSavingTime=Daylight saving time (user) +DaylingSavingTime=Daylight saving time CurrentHour=Hour PHP (server) CompanyTZ= Time Zone company (main company) CompanyHour= Hour company (main company) diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 19199ccbf9fd0cc18d504f5951df94c2f5759bd9..eddd2abff01e3fbfd39debef3a247b928e724c6f 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -108,7 +108,7 @@ OSTZ= Time Zone OS PHPTZ= Time Zone config PHP PHPServerOffsetWithGreenwich= Offset serveur PHP avec Greenwich (secondes) ClientOffsetWithGreenwich= Offset client/navigateur avec Greenwich (secondes) -DaylingSavingTime=Heure d'été (utilisateur) +DaylingSavingTime=Heure d'été CurrentHour= Heure PHP (serveur) CompanyTZ= Time Zone société (maison mère) CompanyHour= Heure société (maison mère) diff --git a/test/phpunit/FunctionsTest.php b/test/phpunit/FunctionsTest.php index 3b54935cf8777da0249f031217abafee306904a7..d0e7025c8a0e3d3e0448071453b98d487f0f32ba 100755 --- a/test/phpunit/FunctionsTest.php +++ b/test/phpunit/FunctionsTest.php @@ -322,9 +322,9 @@ class FunctionsTest extends PHPUnit_Framework_TestCase print __METHOD__." result=".$result."\n"; $this->assertEquals(7261,$result); - $result=dol_mktime(2,0,0,1,1,1970,0); // 1970-01-01 02:00:00 in local area Europe/Paris -> 3600 GMT + $result=dol_mktime(2,0,0,1,1,1970,0); // 1970-01-01 02:00:00 = 7200 in local area Europe/Paris = 3600 GMT print __METHOD__." result=".$result."\n"; - $tz=getServerTimeZoneInt('1970-01-01 02:00:00'); // +1 in Europe/Paris at this time (this time is winter) + $tz=getServerTimeZoneInt('winter'); // +1 in Europe/Paris at this time (this time is winter) $this->assertEquals(7200-($tz*3600),$result); // Should be 7200 if we are at greenwich winter } @@ -337,8 +337,8 @@ class FunctionsTest extends PHPUnit_Framework_TestCase { $now=dol_now('gmt'); $nowtzserver=dol_now('tzserver'); - print __METHOD__."getServerTimeZoneInt=".(getServerTimeZoneInt()*3600)."\n"; - $this->assertEquals(getServerTimeZoneInt()*3600,($nowtzserver-$now)); + print __METHOD__."getServerTimeZoneInt=".(getServerTimeZoneInt('now')*3600)."\n"; + $this->assertEquals(getServerTimeZoneInt('now')*3600,($nowtzserver-$now)); } /**