Skip to content

Commit

Permalink
Merge pull request #23 from paranoiq/master
Browse files Browse the repository at this point in the history
Support for ISO date-time with timezone offset
  • Loading branch information
justinrainbow committed Jan 31, 2013
2 parents 78151a5 + 86631ea commit e260665
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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

0 comments on commit e260665

Please sign in to comment.