Skip to content

Commit b6ce179

Browse files
committed
Fix: allow explicit 0 secfracs in datetime format
1 parent 37810e9 commit b6ce179

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/JsonSchema/Constraints/FormatConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected function validateDateTime($datetime, $format)
138138
// which will fail the above string comparison because the passed
139139
// $datetime may be '2000-05-01T12:12:12.123Z' but format() will return
140140
// '2000-05-01T12:12:12.123000Z'
141-
if ((strpos('u', $format) !== -1) && (intval($dt->format('u')) > 0)) {
141+
if ((strpos('u', $format) !== -1) && (preg_match('/\.\d+Z/', $datetime))) {
142142
return true;
143143
}
144144

tests/JsonSchema/Tests/Constraints/FormatTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function getValidFormats()
8181
array('2000-05-01T12:12:12+01:00', 'date-time'),
8282
array('2000-05-01T12:12:12.123456Z', 'date-time'),
8383
array('2000-05-01T12:12:12.123Z', 'date-time'),
84+
array('2000-05-01T12:12:12.123000Z', 'date-time'),
85+
array('2000-05-01T12:12:12.0Z', 'date-time'),
86+
array('2000-05-01T12:12:12.000Z', 'date-time'),
87+
array('2000-05-01T12:12:12.000000Z', 'date-time'),
8488

8589
array('0', 'utc-millisec'),
8690

@@ -140,6 +144,7 @@ public function getInvalidFormats()
140144
array('1999-1-11T00:00:00Z', 'date-time'),
141145
array('1999-01-11T00:00:00+100', 'date-time'),
142146
array('1999-01-11T00:00:00+1:00', 'date-time'),
147+
array('1999.000Z-01-11T00:00:00+1:00', 'date-time'),
143148

144149
array('-1', 'utc-millisec'),
145150
array(PHP_INT_MAX, 'utc-millisec'),

0 commit comments

Comments
 (0)