Sha256: 844f7fb0f88737124c64101768ffc8d0ad5afb53bea118e47410e04201b02dc3

Contents?: true

Size: 866 Bytes

Versions: 5

Compression:

Stored size: 866 Bytes

Contents

require 'json-schema/attribute'

module JSON
  class Schema
    class DateFormat < FormatAttribute
      REGEXP = /\A\d{4}-\d{2}-\d{2}\z/

      def self.validate(current_schema, data, fragments, processor, validator, options = {})
        if data.is_a?(String)
          error_message = "The property '#{build_fragment(fragments)}' must be a date in the format of YYYY-MM-DD"
          if REGEXP.match(data)
            begin
              Date.parse(data)
            rescue ArgumentError => e
              raise e unless e.message == 'invalid date'
              validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors])
            end
          else
            validation_error(processor, error_message, fragments, current_schema, self, options[:record_errors])
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
json-schema-2.8.0 lib/json-schema/attributes/formats/date.rb
json-schema-2.7.0 lib/json-schema/attributes/formats/date.rb
json-schema-2.6.2 lib/json-schema/attributes/formats/date.rb
json-schema-2.6.1 lib/json-schema/attributes/formats/date.rb
json-schema-2.6.0 lib/json-schema/attributes/formats/date.rb