FIX Timezone management for datetime with modulebuilder

This commit is contained in:
Laurent Destailleur 2021-03-04 09:36:19 +01:00
parent a371647bca
commit 33c4180781
3 changed files with 26 additions and 16 deletions

View File

@ -160,7 +160,7 @@ if ($action == 'update' && !empty($permissiontoadd))
} elseif ($object->fields[$key]['type'] == 'date') {
$value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'));
} elseif ($object->fields[$key]['type'] == 'datetime') {
$value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'));
$value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'), 'tzuserrel');
} elseif ($object->fields[$key]['type'] == 'duration') {
if (GETPOST($key.'hour', 'int') != '' || GETPOST($key.'min', 'int') != '') {
$value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int');

View File

@ -6531,13 +6531,13 @@ abstract class CommonObject
elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value = $this->getLibStatut(3);
elseif ($type == 'date') {
if (!empty($value)) {
$value = dol_print_date($value, 'day');
$value = dol_print_date($value, 'day'); // We suppose dates without time are always gmt (storage of course + output)
} else {
$value = '';
}
} elseif ($type == 'datetime' || $type == 'timestamp') {
if (!empty($value)) {
$value = dol_print_date($value, 'dayhour');
$value = dol_print_date($value, 'dayhour', 'tzuserrel');
} else {
$value = '';
}
@ -7587,11 +7587,13 @@ abstract class CommonObject
*/
public function setVarsFromFetchObj(&$obj)
{
global $db;
foreach ($this->fields as $field => $info)
{
if ($this->isDate($info)) {
if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
else $this->{$field} = strtotime($obj->{$field});
if (is_null($obj->{$field}) || $obj->{$field} === '' || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = '';
else $this->{$field} = $db->jdate($obj->{$field});
} elseif ($this->isArray($info))
{
if (!empty($obj->{$field})) {

View File

@ -103,18 +103,26 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
if (empty($reshook))
{
if ($action == 'seteatby' && $user->rights->stock->creer)
{
$newvalue = dol_mktime(12, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']);
if ($action == 'seteatby' && $user->rights->stock->creer) {
$newvalue = dol_mktime(12, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int'));
$result = $object->setValueFrom('eatby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY');
if ($result < 0) dol_print_error($db, $object->error);
if ($result < 0) {
setEventMessages($object->error, null, 'errors');
$action == 'editeatby';
} else {
$action = 'view';
}
}
if ($action == 'setsellby' && $user->rights->stock->creer)
{
$newvalue = dol_mktime(12, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']);
if ($action == 'setsellby' && $user->rights->stock->creer) {
$newvalue = dol_mktime(12, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int'));
$result = $object->setValueFrom('sellby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY');
if ($result < 0) dol_print_error($db, $object->error);
if ($result < 0) {
setEventMessages($object->error, null, 'errors');
$action == 'editsellby';
} else {
$action = 'view';
}
}
if ($action == 'update_extras')
@ -136,8 +144,9 @@ if (empty($reshook))
}
}
if ($error)
if ($error) {
$action = 'edit_extras';
}
}
// Action to add record
@ -346,7 +355,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '</tr>';
}
// Other attributes
$cols = 2;
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
print '</table>';
@ -391,7 +399,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
* Documents generes
*/
if (empty($action))
if (empty($action) || $action == 'view')
{
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre