diff --git a/htdocs/admin/system/dolibarr.php b/htdocs/admin/system/dolibarr.php index 58fdbbdc473..fc68150819d 100644 --- a/htdocs/admin/system/dolibarr.php +++ b/htdocs/admin/system/dolibarr.php @@ -178,7 +178,7 @@ if (function_exists('date_default_timezone_get')) $var=!$var; print "=> ".$langs->trans("PHPServerOffsetWithGreenwich")."".(-dol_mktime(0,0,0,1,1,1970)>0?'+':'').(-dol_mktime(0,0,0,1,1,1970))."\n"; $var=!$var; -print "=> ".$langs->trans("CurrentHour")."".dol_print_date(dol_now('tzserver'),'dayhour')."\n"; +print "=> ".$langs->trans("CurrentHour")."".dol_print_date(dol_now(),'dayhour','tzserver')."\n"; $var=!$var; print "=> dol_print_date(0,"dayhourtext")'.dol_print_date(0,"dayhourtext").""; $var=!$var; @@ -197,7 +197,7 @@ print "".$langs->trans("ClientTZ")."=> ".$langs->trans("ClientOffsetWithGreenwich")."".($_SESSION['dol_tz']>=0?'+':'').($_SESSION['dol_tz']*60*60)."\n"; $var=!$var; -print "=> ".$langs->trans("ClientHour")."".dol_print_date(dol_now('tzuser'),'dayhour')."\n"; +print "=> ".$langs->trans("ClientHour")."".dol_print_date(dol_now(),'dayhour','tzuser')."\n"; #print "=> ".$langs->trans("ClientHour")."".$langs->trans("FeatureNotYetAvailable")."\n"; $var=!$var; diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php index 906ce9c40fd..2b9b50fea15 100644 --- a/htdocs/cashdesk/validation_verif.php +++ b/htdocs/cashdesk/validation_verif.php @@ -42,7 +42,7 @@ switch ( $_GET['action'] ) $company->fetch($conf->global->CASHDESK_ID_THIRDPARTY); $invoice=new Facture($db); - $invoice->date=dol_now('tzserver'); + $invoice->date=dol_now(); $invoice->type=0; $num=$invoice->getNextNumRef($company); @@ -82,7 +82,7 @@ switch ( $_GET['action'] ) case 'valide_facture': - $now=dol_now('tzserver'); + $now=dol_now(); // Recuperation de la date et de l'heure $date = dol_print_date($now,'day'); diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 6830a398e22..2483ff70a3d 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -110,7 +110,7 @@ class ActionComm extends CommonObject { global $langs,$conf; - $now=dol_now('tzserver'); + $now=dol_now(); // Clean parameters $this->label=dol_trunc(trim($this->label),128); @@ -642,7 +642,7 @@ class ActionComm extends CommonObject if ($cachedelay) { - $nowgmt = dol_now('gmt'); + $nowgmt = dol_now(); if (filemtime($outputfile) > ($nowgmt - $cachedelay)) { dol_syslog("ActionComm::build_exportfile file ".$outputfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay."). Build is canceled"); diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index f9432a12511..6f9e6a207ad 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -568,7 +568,7 @@ class Propal extends CommonObject global $langs,$conf,$mysoc; $error=0; - $now=dol_now('gmt'); + $now=dol_now(); // Clean parameters $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600); @@ -794,7 +794,7 @@ class Propal extends CommonObject $error=0; - $now=dol_now('gmt'); + $now=dol_now(); $object=new Propal($this->db); diff --git a/htdocs/compta/bank/account.php b/htdocs/compta/bank/account.php index af9d626ef00..5f61b9b38dc 100644 --- a/htdocs/compta/bank/account.php +++ b/htdocs/compta/bank/account.php @@ -472,7 +472,7 @@ if ($account || $_GET["ref"]) $result = $db->query($sql); if ($result) { - $now=dol_now('tzserver'); + $now=dol_now(); $nows=dol_date('Ymd',$now); //$html->load_cache_types_paiements(); diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index b137bd9bef4..3576670709f 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -152,7 +152,7 @@ class DiscountAbsolute $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; $sql.= " fk_facture_source"; $sql.= ")"; - $sql.= " VALUES (".$this->db->idate($this->datec!=''?$this->datec:dol_now('tzserver')).", ".$this->fk_soc.", ".$user->id.", '".addslashes($this->description)."',"; + $sql.= " VALUES (".$this->db->idate($this->datec!=''?$this->datec:dol_now()).", ".$this->fk_soc.", ".$user->id.", '".addslashes($this->description)."',"; $sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; $sql.= " ".($this->fk_facture_source?"'".$this->fk_facture_source."'":"null"); $sql.= ")"; diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 0f5e64cb7bb..a354b452674 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -1291,7 +1291,7 @@ if ($step == 5 && $datatoimport) $nboferrors=0; $nbofwarnings=0; - $importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S'); + $importid=dol_print_date(dol_now(),'%Y%m%d%H%M%S'); //var_dump($array_match_file_to_database); @@ -1379,7 +1379,7 @@ if ($step == 5 && $datatoimport) } // Show import id - $importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S'); + $importid=dol_print_date(dol_now(),'%Y%m%d%H%M%S'); print '
'; print $langs->trans("NowClickToRunTheImport",$langs->transnoentitiesnoconv("RunImportFile")).'
'; @@ -1614,7 +1614,7 @@ if ($step == 6 && $datatoimport) $nboferrors=0; $nbofwarnings=0; - $importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S'); + $importid=dol_print_date(dol_now(),'%Y%m%d%H%M%S'); //var_dump($array_match_file_to_database); diff --git a/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php index 052e42fccaf..44d48188fe3 100644 --- a/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -310,7 +310,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures //print "srctemplatepath=".$srctemplatepath; // Src filename $newfile=basename($srctemplatepath); $newfiletmp=preg_replace('/\.odt/i','',$newfile); - $file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S').'.odt'; + $file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; //print "newdir=".$dir; //print "newfile=".$newfile; //print "file=".$file; diff --git a/htdocs/includes/modules/mailings/dolibarr_services_expired.modules.php b/htdocs/includes/modules/mailings/dolibarr_services_expired.modules.php index 73e218f3ec2..86e75b12550 100644 --- a/htdocs/includes/modules/mailings/dolibarr_services_expired.modules.php +++ b/htdocs/includes/modules/mailings/dolibarr_services_expired.modules.php @@ -94,7 +94,7 @@ class mailing_dolibarr_services_expired extends MailingTargets $product=$this->arrayofproducts[$key]; } - $now=dol_now('gmt'); + $now=dol_now(); // La requete doit retourner: id, email, name $sql = " select s.rowid, s.email, s.nom as name, cd.rowid as cdid, cd.date_ouverture, cd.date_fin_validite, cd.fk_contrat"; @@ -173,7 +173,7 @@ class mailing_dolibarr_services_expired extends MailingTargets */ function getNbOfRecipients($filter=1,$option='') { - $now=dol_now('gmt'); + $now=dol_now(); // Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table"); // Example: return 500; diff --git a/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php index 61e4b3423e1..705cc2423c5 100644 --- a/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php @@ -300,7 +300,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc //print "srctemplatepath=".$srctemplatepath; // Src filename $newfile=basename($srctemplatepath); $newfiletmp=preg_replace('/\.odt/i','',$newfile); - $file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S').'.odt'; + $file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; //print "newdir=".$dir; //print "newfile=".$newfile; //print "file=".$file; diff --git a/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php b/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php index 047162a3b09..8bcf6a645f1 100644 --- a/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php +++ b/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php @@ -544,7 +544,7 @@ class InterfaceActionsAuto // Add entry in event table if ($ok) { - $now=dol_now('tzserver'); + $now=dol_now(); // Insertion action require_once(DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'); diff --git a/htdocs/install/etape1.php b/htdocs/install/etape1.php index 9e77787d29a..ebeb7cf1b7a 100644 --- a/htdocs/install/etape1.php +++ b/htdocs/install/etape1.php @@ -522,7 +522,7 @@ function write_conf_file($conffile) fputs($fp, ' we return GMT timestamp, - * 'tzserver' => we use the PHP server timezone - * 'tzref' => we use the company timezone - * 'tzuser' => we use the user timezone - * \return date Timestamp + * Return date for now. We should always use this function without parameters (that means GMT time). + * @param mode 'gmt' => we return GMT timestamp, + * 'tzserver' => we add the PHP server timezone + * 'tzref' => we add the company timezone + * 'tzuser' => we add the user timezone + * @return date Timestamp */ -function dol_now($mode='tzserver') +function dol_now($mode='gmt') { + // Note that gmmktime and mktime return same value (GMT) whithout parameters if ($mode == 'gmt') $ret=gmmktime(); // Time for now at greenwich. - else if ($mode == 'tzserver') // Time for now where PHP server is located + else if ($mode == 'tzserver') // Time for now with PHP server timezone added { - $ret=mktime(); + $tzsecond=-dol_mktime(0,0,0,1,1,1970); + $ret=gmmktime()+$tzsecond; } - else if ($mode == 'tzref') // Time for now where the parent company is located + else if ($mode == 'tzref') // Time for now where parent company timezone is added { - // TODO Should use the timezone of the company instead of timezone of server - $ret=mktime(); + // TODO Should add the company timezone + $ret=gmmktime(); } - else if ($mode == 'tzuser') // Time for now where the user is located + else if ($mode == 'tzuser') // Time for now where user timezone is added { - // TODO Should use the timezone of the user instead of timezone of server - $tz=isset($_SESSION['dol_tz'])?$_SESSION['dol_tz']:0; - $ret=gmmktime()+($tz*24*60*60); + //print 'eeee'.time().'-'.mktime().'-'.gmmktime(); + $tzhour=isset($_SESSION['dol_tz'])?$_SESSION['dol_tz']:0; + $ret=gmmktime()+($tzhour*60*60); } return $ret; } @@ -437,21 +439,49 @@ function dolibarr_print_date($time,$format='',$to_gmt=false,$outputlangs='',$enc /** * Output date in a string format according to outputlangs (or langs if not defined). * Return charset is always UTF-8, except if encodetoouput is defined. In this cas charset is output charset. - * @param time GM Timestamps date (or 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS') + * @param time GM Timestamps date (or deprecated strings 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS') * @param format Output date format * "%d %b %Y", * "%d/%m/%Y %H:%M", * "%d/%m/%Y %H:%M:%S", * "day", "daytext", "dayhour", "dayhourldap", "dayhourtext" - * @param to_gmt false=output string is for local server TZ usage, true=output string is for GMT usage + * @param tzoutput true=output string is for Greenwich location + * false or 'tzserver'=output string is for local PHP server TZ usage + * 'tzuser'=output string is for local browser TZ usage * @param outputlangs Object lang that contains language for text translation. * @return string Formated date or '' if time is null * @see dol_mktime, dol_stringtotime */ -function dol_print_date($time,$format='',$to_gmt=false,$outputlangs='',$encodetooutput=false) +function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$encodetooutput=false) { global $conf,$langs; + $to_gmt=false; + $offset=0; + if ($tzoutput) + { + $to_gmt=true; // For backward compatibility + $offset=0; + if (is_string($tzoutput)) + { + if ($tzoutput == 'tzserver') + { + $to_gmt=false; + $offset=0; + } + if ($tzoutput == 'tzuser') + { + $to_gmt=true; + $offset=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60; + } + if ($tzoutput == 'tzcompany') + { + $to_gmt=false; + $offset=0; // TODO Define this and use it later + } + } + } + if (! is_object($outputlangs)) $outputlangs=$langs; // Si format non defini, on prend $conf->format_date_text_short sinon %Y-%m-%d %H:%M:%S @@ -506,14 +536,14 @@ function dol_print_date($time,$format='',$to_gmt=false,$outputlangs='',$encodeto $ssec = $reg[6]; $time=dol_mktime($shour,$smin,$ssec,$smonth,$sday,$syear,true); - $ret=adodb_strftime($format,$time,$to_gmt); + $ret=adodb_strftime($format,$time+$offset,$to_gmt); } else { // Date is a timestamps if ($time < 100000000000) // Protection against bad date values { - $ret=adodb_strftime($format,$time,$to_gmt); + $ret=adodb_strftime($format,$time+$offset,$to_gmt); } else $ret='Bad value '.$time.' for date'; } @@ -521,7 +551,7 @@ function dol_print_date($time,$format='',$to_gmt=false,$outputlangs='',$encodeto if (preg_match('/__b__/i',$format)) { // Here ret is string in PHP setup language (strftime was used). Now we convert to $outputlangs. - $month=adodb_strftime('%m',$time); + $month=adodb_strftime('%m',$time+$offset); if ($encodetooutput) { $monthtext=$outputlangs->transnoentities('Month'.$month); @@ -540,7 +570,7 @@ function dol_print_date($time,$format='',$to_gmt=false,$outputlangs='',$encodeto } if (preg_match('/__a__/i',$format)) { - $w=adodb_strftime('%w',$time); + $w=adodb_strftime('%w',$time+$offset); $dayweek=$outputlangs->transnoentitiesnoconv('Day'.$w); $ret=str_replace('__A__',$dayweek,$ret); $ret=str_replace('__a__',dol_substr($dayweek,0,3),$ret); diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index ea892177d53..cce01b5f8c3 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -77,7 +77,7 @@ if ($_POST["action"] == 'add' && $user->rights->projet->creer) $project->socid = $_POST["socid"]; $project->description = $_POST["description"]; $project->public = $_POST["public"]; - $project->datec=dol_now('tzserver'); + $project->datec=dol_now(); $project->dateo=dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']); $project->datee=dol_mktime(12,0,0,$_POST['projectendmonth'],$_POST['projectendday'],$_POST['projectendyear']); diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index f8dfc776b30..b8aad6bf000 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -84,7 +84,7 @@ if ($_POST["action"] == 'createtask' && $user->rights->projet->creer) $task->label = $_POST["label"]; $task->description = $_POST['description']; $task->fk_task_parent = $task_parent; - $task->date_c = dol_now('tzserver'); + $task->date_c = dol_now(); $task->date_start = dol_mktime(12,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']); $task->date_end = dol_mktime(12,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']); $task->progress = $_POST['progress'];