Fix that webkit submits datetime values not according to RFC 3339
That's actually more of a workaround instead of a fix as the bug itself is part of webkit, not Icinga Web 2. fixes #8457
This commit is contained in:
parent
3dce0e434a
commit
9c5d44caf0
|
@ -4,7 +4,6 @@
|
||||||
namespace Icinga\Web\Form\Element;
|
namespace Icinga\Web\Form\Element;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Icinga\Web\Form;
|
|
||||||
use Icinga\Web\Form\FormElement;
|
use Icinga\Web\Form\FormElement;
|
||||||
use Icinga\Web\Form\Validator\DateTimeValidator;
|
use Icinga\Web\Form\Validator\DateTimeValidator;
|
||||||
|
|
||||||
|
@ -126,10 +125,17 @@ class DateTimePicker extends FormElement
|
||||||
if (! parent::isValid($value, $context)) {
|
if (! parent::isValid($value, $context)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $value instanceof DateTime) {
|
if (! $value instanceof DateTime) {
|
||||||
$format = $this->local === true ? 'Y-m-d\TH:i:s' : DateTime::RFC3339;
|
$format = $this->local === true ? 'Y-m-d\TH:i:s' : DateTime::RFC3339;
|
||||||
$this->setValue(DateTime::createFromFormat($format, $value));
|
$dateTime = DateTime::createFromFormat($format, $value);
|
||||||
|
if ($dateTime === false) {
|
||||||
|
$dateTime = DateTime::createFromFormat(substr($format, 0, strrpos($format, ':')), $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->setValue($dateTime);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,14 +57,22 @@ class DateTimeValidator extends Zend_Validate_Abstract
|
||||||
$this->_error(self::INVALID_DATETIME_TYPE);
|
$this->_error(self::INVALID_DATETIME_TYPE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (is_string($value)) {
|
|
||||||
$format = $this->local === true ? 'Y-m-d\TH:i:s' : DateTime::RFC3339;
|
if (! $value instanceof DateTime) {
|
||||||
|
$format = $baseFormat = $this->local === true ? 'Y-m-d\TH:i:s' : DateTime::RFC3339;
|
||||||
$dateTime = DateTime::createFromFormat($format, $value);
|
$dateTime = DateTime::createFromFormat($format, $value);
|
||||||
|
|
||||||
|
if ($dateTime === false) {
|
||||||
|
$format = substr($format, 0, strrpos($format, ':'));
|
||||||
|
$dateTime = DateTime::createFromFormat($format, $value);
|
||||||
|
}
|
||||||
|
|
||||||
if ($dateTime === false || $dateTime->format($format) !== $value) {
|
if ($dateTime === false || $dateTime->format($format) !== $value) {
|
||||||
$this->_error(self::INVALID_DATETIME_FORMAT, DateTimeFactory::create()->format($format));
|
$this->_error(self::INVALID_DATETIME_FORMAT, DateTimeFactory::create()->format($baseFormat));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue