diff --git a/lib/json-schema/attributes/format.rb b/lib/json-schema/attributes/format.rb index 6af347e7..05e7e78f 100644 --- a/lib/json-schema/attributes/format.rb +++ b/lib/json-schema/attributes/format.rb @@ -4,12 +4,12 @@ class FormatAttribute < Attribute def self.validate(current_schema, data, fragments, validator, options = {}) case current_schema.schema['format'] - # Timestamp in restricted ISO-8601 YYYY-MM-DDThh:mm:ssZ + # Timestamp in restricted ISO-8601 YYYY-MM-DDThh:mm:ssZ with optional decimal fraction of the second when 'date-time' if data.is_a?(String) - error_message = "The property '#{build_fragment(fragments)}' must be a date/time in the ISO-8601 format of YYYY-MM-DDThh:mm:ssZ" + error_message = "The property '#{build_fragment(fragments)}' must be a date/time in the ISO-8601 format of YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss.ssZ" validation_error(error_message, fragments, current_schema, self, options[:record_errors]) and return if !data.is_a?(String) - r = Regexp.new('^\d\d\d\d-\d\d-\d\dT(\d\d):(\d\d):(\d\d)Z$') + r = Regexp.new('^\d\d\d\d-\d\d-\d\dT(\d\d):(\d\d):(\d\d)([\.,]\d+)?Z$') if (m = r.match(data)) parts = data.split("T") begin diff --git a/test/test_jsonschema_draft3.rb b/test/test_jsonschema_draft3.rb index e0a48063..55ef65bd 100644 --- a/test/test_jsonschema_draft3.rb +++ b/test/test_jsonschema_draft3.rb @@ -925,6 +925,10 @@ def test_format_datetime data = {"a" => "2010-01-01T12:00:00Z"} assert(JSON::Validator.validate(schema,data)) + data = {"a" => "2010-01-01T12:00:00.1Z"} + assert(JSON::Validator.validate(schema,data)) + data = {"a" => "2010-01-01T12:00:00,1Z"} + assert(JSON::Validator.validate(schema,data)) data = {"a" => "2010-01-32T12:00:00Z"} assert(!JSON::Validator.validate(schema,data)) data = {"a" => "2010-13-01T12:00:00Z"}