Skip to content

Support for ISO date-time with timezone offset #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/JsonSchema/Constraints/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public function check($element, $schema = null, $path = null, $i = null)
break;

case 'date-time':
if (!$this->validateDateTime($element, 'Y-m-d\TH:i:s\Z')) {
$this->addError($path, sprintf('Invalid date time %s, expected format YYYY-MM-DDTHH:MM:SSZ', json_encode($element)));
if (!$this->validateDateTime($element, 'Y-m-d\TH:i:s\Z') &&
!$this->validateDateTime($element, 'Y-m-d\TH:i:sP')
) {
$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;

Expand Down Expand Up @@ -155,4 +157,4 @@ protected function validateHostname($host)
{
return preg_match('/^[_a-z]+\.([_a-z]+\.?)+$/i', $host);
}
}
}
2 changes: 2 additions & 0 deletions tests/JsonSchema/Tests/Constraints/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function getValidFormats()
array('23:59:59', 'time'),

array('2000-05-01T12:12:12Z', 'date-time'),
array('2000-05-01T12:12:12+01:00', 'date-time'),

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

Expand Down Expand Up @@ -127,6 +128,7 @@ public function getInvalidFormats()
array('25:00:00', 'time'),

array('1999-1-11T00:00:00Z', 'date-time'),
array('1999-01-11T00:00:00+1:00', 'date-time'),

array('-1', 'utc-millisec'),
array(PHP_INT_MAX, 'utc-millisec'),
Expand Down