From 1215762f043b90d9b016f57826c8a6a49829a1ef Mon Sep 17 00:00:00 2001 From: ralf Date: Tue, 3 May 2022 09:46:15 +0200 Subject: [PATCH] if data_format given, try that first, before leaving it to Api\DateTime to figure it out --- api/src/Etemplate/Widget/Customfields.php | 8 ++++---- api/src/Etemplate/Widget/Date.php | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/src/Etemplate/Widget/Customfields.php b/api/src/Etemplate/Widget/Customfields.php index aa795cfd0a..697e3c0d9e 100644 --- a/api/src/Etemplate/Widget/Customfields.php +++ b/api/src/Etemplate/Widget/Customfields.php @@ -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 */ diff --git a/api/src/Etemplate/Widget/Date.php b/api/src/Etemplate/Widget/Date.php index 73dc0671c5..e4b2568cb5 100644 --- a/api/src/Etemplate/Widget/Date.php +++ b/api/src/Etemplate/Widget/Date.php @@ -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); }