Skip to content

Commit

Permalink
Merge remote branch 'ILikePies/master' into merge-vapir
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxworth committed May 29, 2012
2 parents a671cf2 + 6e08858 commit aad2ffa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/json-schema/attributes/format.rb
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/test_jsonschema_draft3.rb
Expand Up @@ -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"}
Expand Down

0 comments on commit aad2ffa

Please sign in to comment.