Sha256: 9672209db6f752279d9ad64bd43dce2d65db4928f3899508648b1b1f0191a76e
Contents?: true
Size: 1.71 KB
Versions: 1
Compression:
Stored size: 1.71 KB
Contents
require 'json-schema/attribute' require 'uri' module JSON class Schema class DateTimeFormat < FormatAttribute def self.validate(current_schema, data, fragments, processor, validator, options = {}) # Timestamp in restricted ISO-8601 YYYY-MM-DDThh:mm:ssZ with optional decimal fraction of the second 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 or YYYY-MM-DDThh:mm:ss.ssZ" r = Regexp.new('^\d\d\d\d-\d\d-\d\dT(\d\d):(\d\d):(\d\d)([\.,]\d+)?(Z|[+-](\d\d)(:?\d\d)?)?$') if (m = r.match(data)) parts = data.split("T") begin Date.parse(parts[0]) rescue Exception validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) return end begin validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if m[1].to_i > 23 validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if m[2].to_i > 59 validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) and return if m[3].to_i > 59 rescue Exception validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) return end else validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors]) return end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
json-schema-2.3.0 | lib/json-schema/attributes/formats/date_time.rb |