allow to specify a date-format in custom-fields using eg. format=Ymd, as it was possible in 11.1 in len field

This commit is contained in:
Ralf Becker 2017-11-10 17:30:20 +01:00
parent 43927f0bd5
commit b408c8b464
2 changed files with 11 additions and 3 deletions

View File

@ -298,7 +298,14 @@ class Customfields extends Transformer
{ {
case 'date': case 'date':
case 'date-time': case 'date-time':
if (!empty($field['values']['format']))
{
$widget->attrs['dataformat'] = $field['values']['format'];
}
else
{
$widget->attrs['dataformat'] = $type == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s'; $widget->attrs['dataformat'] = $type == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s';
}
if($field['values']['min']) $widget->attrs['min'] = $field['values']['min']; if($field['values']['min']) $widget->attrs['min'] = $field['values']['min'];
if($field['values']['max']) $widget->attrs['min'] = $field['values']['max']; if($field['values']['max']) $widget->attrs['min'] = $field['values']['max'];
break; break;

View File

@ -107,7 +107,7 @@ class Date extends Transformer
{ {
if (!$value) return $value; // otherwise we will get current date or 1970-01-01 instead of an empty value if (!$value) return $value; // otherwise we will get current date or 1970-01-01 instead of an empty value
if ($this->attrs['dataformat'] && !is_numeric($value)) if ($this->attrs['dataformat'])
{ {
$date = Api\DateTime::createFromFormat($this->attrs['dataformat'], $value, Api\DateTime::$user_timezone); $date = Api\DateTime::createFromFormat($this->attrs['dataformat'], $value, Api\DateTime::$user_timezone);
} }
@ -158,6 +158,7 @@ class Date extends Transformer
} }
catch(\Exception $e) catch(\Exception $e)
{ {
unset($e);
$date = null; $date = null;
$value = ''; $value = '';
// this is not really a user error, but one of the clientside engine // this is not really a user error, but one of the clientside engine