diff --git a/src/JsonSchema/Constraints/FormatConstraint.php b/src/JsonSchema/Constraints/FormatConstraint.php index c7897538..85a33e28 100644 --- a/src/JsonSchema/Constraints/FormatConstraint.php +++ b/src/JsonSchema/Constraints/FormatConstraint.php @@ -138,7 +138,7 @@ protected function validateDateTime($datetime, $format) // which will fail the above string comparison because the passed // $datetime may be '2000-05-01T12:12:12.123Z' but format() will return // '2000-05-01T12:12:12.123000Z' - if ((strpos('u', $format) !== -1) && (intval($dt->format('u')) > 0)) { + if ((strpos('u', $format) !== -1) && (preg_match('/\.\d+Z/', $datetime))) { return true; } diff --git a/tests/JsonSchema/Tests/Constraints/FormatTest.php b/tests/JsonSchema/Tests/Constraints/FormatTest.php index eb47983d..f604c083 100644 --- a/tests/JsonSchema/Tests/Constraints/FormatTest.php +++ b/tests/JsonSchema/Tests/Constraints/FormatTest.php @@ -81,6 +81,10 @@ public function getValidFormats() array('2000-05-01T12:12:12+01:00', 'date-time'), array('2000-05-01T12:12:12.123456Z', 'date-time'), array('2000-05-01T12:12:12.123Z', 'date-time'), + array('2000-05-01T12:12:12.123000Z', 'date-time'), + array('2000-05-01T12:12:12.0Z', 'date-time'), + array('2000-05-01T12:12:12.000Z', 'date-time'), + array('2000-05-01T12:12:12.000000Z', 'date-time'), array('0', 'utc-millisec'), @@ -140,6 +144,7 @@ public function getInvalidFormats() array('1999-1-11T00:00:00Z', 'date-time'), array('1999-01-11T00:00:00+100', 'date-time'), array('1999-01-11T00:00:00+1:00', 'date-time'), + array('1999.000Z-01-11T00:00:00+1:00', 'date-time'), array('-1', 'utc-millisec'), array(PHP_INT_MAX, 'utc-millisec'),