From 86631ea1421ea52d59a7215fa41901cef089c686 Mon Sep 17 00:00:00 2001 From: Vlasta Neubauer Date: Tue, 1 Jan 2013 16:57:00 +0100 Subject: [PATCH] support for ISO 8601 date-times including UTC offset --- src/JsonSchema/Constraints/Format.php | 8 +++++--- tests/JsonSchema/Tests/Constraints/FormatTest.php | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/JsonSchema/Constraints/Format.php b/src/JsonSchema/Constraints/Format.php index 18c3898a..a5bd5922 100644 --- a/src/JsonSchema/Constraints/Format.php +++ b/src/JsonSchema/Constraints/Format.php @@ -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; @@ -155,4 +157,4 @@ protected function validateHostname($host) { return preg_match('/^[_a-z]+\.([_a-z]+\.?)+$/i', $host); } -} \ No newline at end of file +} diff --git a/tests/JsonSchema/Tests/Constraints/FormatTest.php b/tests/JsonSchema/Tests/Constraints/FormatTest.php index b1745652..06331f50 100644 --- a/tests/JsonSchema/Tests/Constraints/FormatTest.php +++ b/tests/JsonSchema/Tests/Constraints/FormatTest.php @@ -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'), @@ -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'),