N°7145 - UI - Init Value DateTime and Date with Day Time

This commit is contained in:
Eric Espie
2025-01-06 16:52:32 +01:00
parent 73bb80ebea
commit 301a7a92a0
3 changed files with 138 additions and 5 deletions

View File

@@ -6347,7 +6347,11 @@ class AttributeDateTime extends AttributeDBField
$oFormField = parent::MakeFormField($oObject, $oFormField);
// After call to the parent as it sets the current value
$oFormField->SetCurrentValue($this->GetFormat()->Format($oObject->Get($this->GetCode())));
$oValue = $oObject->Get($this->GetCode());
if ($oValue === $this->GetNullValue()) {
$oValue = $this->GetDefaultValue($oObject);
}
$oFormField->SetCurrentValue($this->GetFormat()->Format($oValue));
return $oFormField;
}
@@ -6433,8 +6437,20 @@ class AttributeDateTime extends AttributeDBField
public function GetDefaultValue(DBObject $oHostObject = null)
{
if (!$this->IsNullAllowed()) {
return date($this->GetInternalFormat());
$sDefaultValue = $this->Get('default_value');
if (!$this->IsNullAllowed() && $sDefaultValue !== '') {
try {
$oDate = new DateTimeImmutable($sDefaultValue);
}
catch (Exception $e) {
IssueLog::Error($e->getMessage(), null, [
'class' => get_class($this),
'name' => $this->GetCode(),
'stack' => $e->getTraceAsString()]);
return $this->GetNullValue();
}
return $oDate->format($this->GetInternalFormat());
}
return $this->GetNullValue();
}