if data_format given, try that first, before leaving it to Api\DateTime to figure it out

This commit is contained in:
ralf 2022-05-03 09:46:15 +02:00
parent 582459242f
commit 1215762f04
2 changed files with 9 additions and 7 deletions

View File

@ -24,11 +24,11 @@ class Customfields extends Transformer
{
/**
* Allowd types of customfields
* Allowed types of customfields
*
* The additionally allowed app-names from the link-class, will be add by the edit-method only,
* as the link-class has to be called, which can NOT be instanciated by the constructor, as
* we get a loop in the instanciation.
* The additionally allowed app-names from the link-class, will be added by the edit-method only,
* as the link-class has to be called, which can NOT be instantiated by the constructor, as
* we get a loop in the instantiation.
*
* @var array
*/

View File

@ -120,15 +120,17 @@ class Date extends Transformer
{
$date = Api\DateTime::server2user($value);
}
elseif (!empty($this->attrs['data_format']) && $this->attrs['data_format'] !== 'object')
// if data_format given, try that first, before leaving it to Api\DateTime to figure it out
elseif (!empty($this->attrs['data_format']) && $this->attrs['data_format'] !== 'object' &&
($date = Api\DateTime::createFromFormat($this->attrs['data_format'], $value, Api\DateTime::$user_timezone)))
{
$date = Api\DateTime::createFromFormat($this->attrs['data_format'], $value, Api\DateTime::$user_timezone);
// set AND checked above
}
else
{
$date = new Api\DateTime($value);
}
if($this->type == 'date-timeonly' && $date)
if($this->type === 'date-timeonly' && $date)
{
$date->setDate(1970, 1, 1);
}