You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And in the function FormatConstraint::check the case 'date-time' should be changed to:
case 'date-time':
if (!$this->validateDateTime($element, 'Y-m-d\TH:i:sT') &&
!$this->validateDateTime($element, 'Y-m-d\TH:i:s.uT') &&
!$this->validateDateTime($element, 'Y-m-d\TH:i:sP') &&
!$this->validateDateTime($element, 'Y-m-d\TH:i:s.uP') &&
!$this->validateDateTime($element, 'Y-m-d\TH:i:sO') &&
!$this->validateDateTime($element, 'Y-m-d\TH:i:s.uO')
) {
$this->addError($path, sprintf('Invalid date-time %s, expected format YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss+hh:mm', json_encode($element)));
}
break;
The T is better than \Z because this way the timezone part from the string will be correctly read. Important if the script is not running with UTC timezone. And the FormatConstraint::validateDateTime can now be changed to this, so that the tests will work:
protected function validateDateTime($datetime, $format)
{
$dt = \DateTime::createFromFormat($format, $datetime);
if (!$dt) {
return false;
}
if (strpos($format, '.u') > 0 ) {
$dtTest = new \DateTime($datetime);
return $dt == $dtTest;
}
return $datetime === $dt->format($format);
}
So that when a fraction is included in the datetime string, it will be checked if reading from format and just a plain DateTime instance will have the same value.
The text was updated successfully, but these errors were encountered:
The date-time is not handling the fraction part of a datetime string correctly
To the FormatTest::getValidFormats should be added following cases:
And in the function FormatConstraint::check the case 'date-time' should be changed to:
The T is better than \Z because this way the timezone part from the string will be correctly read. Important if the script is not running with UTC timezone. And the FormatConstraint::validateDateTime can now be changed to this, so that the tests will work:
So that when a fraction is included in the datetime string, it will be checked if reading from format and just a plain DateTime instance will have the same value.
The text was updated successfully, but these errors were encountered: