diff --git a/library/Reporting/Web/Forms/TimeframeForm.php b/library/Reporting/Web/Forms/TimeframeForm.php index 351cd78..2194a0b 100644 --- a/library/Reporting/Web/Forms/TimeframeForm.php +++ b/library/Reporting/Web/Forms/TimeframeForm.php @@ -46,16 +46,10 @@ protected function assemble() 'description' => $this->translate('A unique name of this timeframe') ]); - $default = new DateTime('00:00:00'); - $start = $this->getPopulatedValue('start', $default); - if (! $start instanceof DateTime) { - $datetime = DateTime::createFromFormat(LocalDateTimeElement::FORMAT, $start); - if ($datetime) { - $start = $datetime; - } - } - - $relativeStart = $this->getPopulatedValue('relative-start', $start instanceof DateTime ? 'n' : 'y'); + $start = $this->getPopulatedValue('start', new DateTime('00:00:00')); + $canBeConverted = $start instanceof DateTime + || DateTime::createFromFormat(LocalDateTimeElement::FORMAT, $start) !== false; + $relativeStart = $this->getPopulatedValue('relative-start', $canBeConverted ? 'n' : 'y'); $this->addElement('checkbox', 'relative-start', [ 'required' => false, 'class' => 'autosubmit', @@ -65,7 +59,7 @@ protected function assemble() if ($relativeStart === 'n') { if (! $start instanceof DateTime) { - $start = $default; + $start = (new DateTime($start))->format(LocalDateTimeElement::FORMAT); $this->clearPopulatedValue('start'); } @@ -102,16 +96,10 @@ protected function assemble() ]); } - $default = new DateTime('23:59:59'); - $end = $this->getPopulatedValue('end', $default); - if (! $end instanceof DateTime) { - $datetime = DateTime::createFromFormat(LocalDateTimeElement::FORMAT, $end); - if ($datetime) { - $end = $datetime; - } - } - - $relativeEnd = $this->getPopulatedValue('relative-end', $end instanceof DateTime ? 'n' : 'y'); + $end = $this->getPopulatedValue('end', new DateTime('23:59:59')); + $canBeConverted = $end instanceof DateTime + || DateTime::createFromFormat(LocalDateTimeElement::FORMAT, $end) !== false; + $relativeEnd = $this->getPopulatedValue('relative-end', $canBeConverted ? 'n' : 'y'); if ($relativeStart === 'y') { $this->addElement('checkbox', 'relative-end', [ 'required' => false, @@ -153,7 +141,7 @@ protected function assemble() if ($relativeEnd === 'n' || $relativeStart === 'n') { if (! $end instanceof DateTime) { - $end = $default; + $end = (new DateTime($end))->format(LocalDateTimeElement::FORMAT); $this->clearPopulatedValue('end'); }