Class: JSON::Schema::DateTimeFormat
- Inherits:
-
FormatAttribute
- Object
- Attribute
- FormatAttribute
- JSON::Schema::DateTimeFormat
- Defined in:
- lib/json-schema/attributes/formats/date_time.rb
Constant Summary
Constants inherited from Attribute
Attribute::TYPE_CLASS_MAPPINGS
Class Method Summary collapse
Methods inherited from Attribute
build_fragment, data_valid_for_type?, validation_error, validation_errors
Class Method Details
.validate(current_schema, data, fragments, processor, validator, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/json-schema/attributes/formats/date_time.rb', line 6 def self.validate(current_schema, data, fragments, processor, validator, = {}) # Timestamp in restricted ISO-8601 YYYY-MM-DDThh:mm:ssZ with optional decimal fraction of the second if data.is_a?(String) = "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, , fragments, current_schema, self, [:record_errors]) return end begin validation_error(processor, , fragments, current_schema, self, [:record_errors]) and return if m[1].to_i > 23 validation_error(processor, , fragments, current_schema, self, [:record_errors]) and return if m[2].to_i > 59 validation_error(processor, , fragments, current_schema, self, [:record_errors]) and return if m[3].to_i > 59 rescue Exception validation_error(processor, , fragments, current_schema, self, [:record_errors]) return end else validation_error(processor, , fragments, current_schema, self, [:record_errors]) return end end end |