diff --git a/htdocs/admin/system/dolibarr.php b/htdocs/admin/system/dolibarr.php index c357d0148d4..1dfe1eb03e7 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 ''.$langs->trans("CurrentTimeZone").''; // 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 ''."\n"; // value defined in http://fr3.php.net/manual/en/timezones.europe.php $var=!$var; print '  => '.$langs->trans("CurrentHour").''.dol_print_date(dol_now(),'dayhour','tzserver').''."\n"; diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 7e741918d72..f7be31e1565 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 e39e3feee25..d683a09bd75 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 45a683afbc2..93fa494623c 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 '
'; } @@ -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 '
'; } @@ -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 '
'; } @@ -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 '
'; } @@ -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 '
'; } @@ -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 '
'; } // 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 '
'; } } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 48b1c14a998..0fa4d7677de 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/en_US/products.lang b/htdocs/langs/en_US/products.lang index 0dfb6cb9eac..527526d9268 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -104,7 +104,7 @@ BarCode=Barcode BarcodeType=Barcode type SetDefaultBarcodeType=Set barcode type BarcodeValue=Barcode value -GenbarcodeLocation=Bar code generation command line tool (used by phpbarcode engine for some bar code types) +GenbarcodeLocation=Bar code generation command line tool (used by internal engine for some bar code types) NoteNotVisibleOnBill=Note (not visible on invoices, proposals...) CreateCopy=Create copy ServiceLimitedDuration=If product is a service with limited duration: diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 19199ccbf9f..eddd2abff01 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/scripts/invoices/rebuild_merge_pdf.php b/scripts/invoices/rebuild_merge_pdf.php index 842bf467e2f..45f112e071b 100644 --- a/scripts/invoices/rebuild_merge_pdf.php +++ b/scripts/invoices/rebuild_merge_pdf.php @@ -181,8 +181,8 @@ if (in_array('date',$filter)) if (empty($sqlwhere)) $sqlwhere=' WHERE '; else $sqlwhere.=" AND"; $sqlwhere.= " f.fk_statut > 0"; - $sqlwhere.= " AND f.datef >= ".$db->idate($dateafterdate); - $sqlwhere.= " AND f.datef <= ".$db->idate($datebeforedate); + $sqlwhere.= " AND f.datef >= '".$db->idate($dateafterdate)."'"; + $sqlwhere.= " AND f.datef <= '".$db->idate($datebeforedate)."'"; $sqlorder = " ORDER BY f.datef ASC"; } if (in_array('nopayment',$filter)) @@ -202,8 +202,8 @@ if (in_array('payments',$filter)) $sqlwhere.= " f.fk_statut > 0"; $sqlwhere.= " AND f.rowid = pf.fk_facture"; $sqlwhere.= " AND pf.fk_paiement = p.rowid"; - $sqlwhere.= " AND p.datep >= ".$db->idate($paymentdateafter); - $sqlwhere.= " AND p.datep <= ".$db->idate($paymentdatebefore); + $sqlwhere.= " AND p.datep >= '".$db->idate($paymentdateafter)."'"; + $sqlwhere.= " AND p.datep <= '".$db->idate($paymentdatebefore)."'"; $sqlorder = " ORDER BY p.datep ASC"; } if (in_array('nodeposit',$filter)) diff --git a/test/phpunit/FunctionsTest.php b/test/phpunit/FunctionsTest.php index 3b54935cf87..d0e7025c8a0 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)); } /** diff --git a/test/phpunit/PgsqlTest.php b/test/phpunit/PgsqlTest.php index 18ec1246547..41e37b22a44 100755 --- a/test/phpunit/PgsqlTest.php +++ b/test/phpunit/PgsqlTest.php @@ -27,6 +27,7 @@ global $conf,$user,$langs,$db; //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver require_once 'PHPUnit/Autoload.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; +require_once dirname(__FILE__).'/../../htdocs/core/db/pgsql.class.php'; $langs->load("dict"); if (empty($user->id))