";
}
diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php
index a1800e03980..3191e5edd47 100644
--- a/htdocs/core/class/conf.class.php
+++ b/htdocs/core/class/conf.class.php
@@ -102,6 +102,8 @@ class Conf
public $liste_limit;
+ public $tzuserinputkey = 'tzserver'; // Use 'tzuserrel' to always store date in GMT and show date in time zone of user.
+
/**
* Constructor
@@ -693,6 +695,8 @@ class Conf
if (defined('MAIN_ANTIVIRUS_COMMAND')) $this->global->MAIN_ANTIVIRUS_COMMAND = constant('MAIN_ANTIVIRUS_COMMAND');
if (defined('MAIN_ANTIVIRUS_PARAM')) $this->global->MAIN_ANTIVIRUS_PARAM = constant('MAIN_ANTIVIRUS_PARAM');
+ if (!empty($this->global->MAIN_TZUSERINPUTKEY)) $this->tzuserinputkey = $this->global->MAIN_TZUSERINPUTKEY; // 'tzserver' or 'tzuserrel'
+
// For backward compatibility
if (isset($this->product)) $this->produit = $this->product;
if (isset($this->facture)) $this->invoice = $this->facture;
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 4ed39694720..ed0511a8e1d 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -5531,13 +5531,18 @@ class Form
* @param int $stepminutes Specify step for minutes between 1 and 30
* @param string $labeladddateof Label to use for the $adddateof parameter.
* @param string $placeholder Placeholder
+ * @param mixed $gm 'auto', 'gmt' or 'tzserver' or 'tzuserrel'
* @return string Html for selectDate
* @see form_date(), select_month(), select_year(), select_dayofweek()
*/
- public function selectDate($set_time = '', $prefix = 're', $h = 0, $m = 0, $empty = 0, $form_name = "", $d = 1, $addnowlink = 0, $disabled = 0, $fullday = '', $addplusone = '', $adddateof = '', $openinghours = '', $stepminutes = 1, $labeladddateof = '', $placeholder = '')
+ public function selectDate($set_time = '', $prefix = 're', $h = 0, $m = 0, $empty = 0, $form_name = "", $d = 1, $addnowlink = 0, $disabled = 0, $fullday = '', $addplusone = '', $adddateof = '', $openinghours = '', $stepminutes = 1, $labeladddateof = '', $placeholder = '', $gm = 'auto')
{
global $conf, $langs;
+ if ($gm == 'auto') {
+ $gm = $conf->tzuserinputkey;
+ }
+
$retstring = '';
if ($prefix == '') $prefix = 're';
@@ -5553,7 +5558,11 @@ class Form
if ($set_time === '' && $emptydate == 0)
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
- $set_time = dol_now('tzuser') - (getServerTimeZoneInt('now') * 3600); // set_time must be relative to PHP server timezone
+ if ($gm == 'tzuser' || $gm == 'tzuserrel') {
+ $set_time = dol_now($gm);
+ } else {
+ $set_time = dol_now('tzuser') - (getServerTimeZoneInt('now') * 3600); // set_time must be relative to PHP server timezone
+ }
}
// Analysis of the pre-selection date
@@ -5569,14 +5578,14 @@ class Form
} elseif (strval($set_time) != '' && $set_time != -1)
{
// set_time est un timestamps (0 possible)
- $syear = dol_print_date($set_time, "%Y");
- $smonth = dol_print_date($set_time, "%m");
- $sday = dol_print_date($set_time, "%d");
+ $syear = dol_print_date($set_time, "%Y", $gm);
+ $smonth = dol_print_date($set_time, "%m", $gm);
+ $sday = dol_print_date($set_time, "%d", $gm);
if ($orig_set_time != '')
{
- $shour = dol_print_date($set_time, "%H");
- $smin = dol_print_date($set_time, "%M");
- $ssec = dol_print_date($set_time, "%S");
+ $shour = dol_print_date($set_time, "%H", $gm);
+ $smin = dol_print_date($set_time, "%M", $gm);
+ $ssec = dol_print_date($set_time, "%S", $gm);
} else {
$shour = '';
$smin = '';
diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php
index 163f6d85b6d..3a889367dc1 100644
--- a/htdocs/core/lib/date.lib.php
+++ b/htdocs/core/lib/date.lib.php
@@ -465,9 +465,10 @@ function dol_get_next_week($day, $week, $month, $year)
*
* @param int $year Year
* @param int $month Month
- * @param mixed $gm False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
- * Exemple: dol_get_first_day(1970,1,false) will return -3600 with TZ+1, a dol_print_date on it will return 1970-01-01 00:00:00
- * Exemple: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, a dol_print_date on it will return 1970-01-01 00:00:00
+ * @param mixed $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
+ * True or 1 or 'gmt' to compare with GMT date.
+ * Example: dol_get_first_day(1970,1,false) will return -3600 with TZ+1, a dol_print_date on it will return 1970-01-01 00:00:00
+ * Example: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, a dol_print_date on it will return 1970-01-01 00:00:00
* @return int Date for first day, '' if error
*/
function dol_get_first_day($year, $month = 1, $gm = false)
@@ -481,7 +482,8 @@ function dol_get_first_day($year, $month = 1, $gm = false)
*
* @param int $year Year
* @param int $month Month
- * @param boolean $gm False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
+ * @param mixed $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
+ * True or 1 or 'gmt' to compare with GMT date.
* @return int Date for first day, '' if error
*/
function dol_get_last_day($year, $month = 12, $gm = false)
@@ -529,7 +531,8 @@ function dol_get_first_hour($date)
* @param int $day Day
* @param int $month Month
* @param int $year Year
- * @param int $gm False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date.
+ * @param mixed $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
+ * True or 1 or 'gmt' to compare with GMT date.
* @return array year,month,week,first_day,first_month,first_year,prev_day,prev_month,prev_year
*/
function dol_get_first_day_week($day, $month, $year, $gm = false)
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index ecfb46dc589..e1d64da77f1 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -1971,10 +1971,14 @@ function dol_strftime($fmt, $ts = false, $is_gmt = false)
*
* @see dol_mktime(), dol_stringtotime(), dol_getdate()
*/
-function dol_print_date($time, $format = '', $tzoutput = 'tzserver', $outputlangs = '', $encodetooutput = false)
+function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = '', $encodetooutput = false)
{
global $conf, $langs;
+ if ($tzoutput == 'auto') {
+ $tzoutput = $conf->tzuserinputkey;
+ }
+
// Clean parameters
$to_gmt = false;
$offsettz = $offsetdst = 0;
@@ -2184,17 +2188,23 @@ function dol_getdate($timestamp, $fast = false, $forcetimezone = '')
* @param int $year Year
* @param mixed $gm True or 1 or 'gmt'=Input informations are GMT values
* False or 0 or 'tzserver' = local to server TZ
- * 'tzuser' = local to user TZ
+ * 'auto'
+ * 'tzuser' = local to user TZ taking dst into account at the current date. Not yet implemented.
+ * 'tzuserrel' = local to user TZ taking dst into account at the given date. Use this one to convert date input from user.
* 'tz,TimeZone' = use specified timezone
* @param int $check 0=No check on parameters (Can use day 32, etc...)
* @return int|string Date as a timestamp, '' or false if error
* @see dol_print_date(), dol_stringtotime(), dol_getdate()
*/
-function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = 'tzserver', $check = 1)
+function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = 'auto', $check = 1)
{
global $conf;
//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
+ if ($gm == 'auto') {
+ $gm = $conf->tzuserinputkey;
+ }
+
// Clean parameters
if ($hour == -1 || empty($hour)) $hour = 0;
if ($minute == -1 || empty($minute)) $minute = 0;
@@ -2215,7 +2225,7 @@ function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = 'tzserve
{
$default_timezone = @date_default_timezone_get(); // Example 'Europe/Berlin'
$localtz = new DateTimeZone($default_timezone);
- } elseif ($gm === 'user' || $gm === 'tzuser')
+ } elseif ($gm === 'user' || $gm === 'tzuser' || $gm === 'tzuserrel')
{
// We use dol_tz_string first because it is more reliable.
$default_timezone = (empty($_SESSION["dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION["dol_tz_string"]); // Example 'Europe/Berlin'
@@ -2254,16 +2264,21 @@ function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = 'tzserve
/**
* Return date for now. In most cases, we use this function without parameters (that means GMT time).
*
- * @param string $mode 'gmt' => we return GMT timestamp,
+ * @param string $mode 'auto'
+ * 'gmt' => we return GMT timestamp,
* 'tzserver' => we add the PHP server timezone
- * 'tzref' => we add the company timezone
- * 'tzuser' => we add the user timezone
+ * 'tzref' => we add the company timezone. Not implemented.
+ * 'tzuser' or 'tzuserrel' => we add the user timezone
* @return int $date Timestamp
*/
-function dol_now($mode = 'gmt')
+function dol_now($mode = 'auto')
{
$ret = 0;
+ if ($mode == 'auto') {
+ $mode = 'tzserver';
+ }
+
if ($mode == 'gmt') $ret = time(); // Time for now at greenwich.
elseif ($mode == 'tzserver') // Time for now with PHP server timezone added
{
@@ -2276,7 +2291,7 @@ function dol_now($mode = 'gmt')
$tzsecond=getParentCompanyTimeZoneInt(); // Contains tz+dayling saving time
$ret=dol_now('gmt')+($tzsecond*3600);
}*/
- elseif ($mode == 'tzuser') // Time for now with user timezone added
+ elseif ($mode == 'tzuser' || $mode == 'tzuserrel') // Time for now with user timezone added
{
//print 'time: '.time();
$offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60;
diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php
index a77f38f8f66..ffc79b8f4b4 100644
--- a/htdocs/core/lib/functions2.lib.php
+++ b/htdocs/core/lib/functions2.lib.php
@@ -246,8 +246,8 @@ function dol_print_object_info($object, $usetable = 0)
print $langs->trans("DateCreation");
if ($usetable) print '