Sha256: 0bee6d821746f0a031ba46785f3a4f6bff1b59aac1243f483c6caada84c2affb

Contents?: true

Size: 874 Bytes

Versions: 6

Compression:

Stored size: 874 Bytes

Contents

require 'json-schema/attributes/format'

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

6 entries across 5 versions & 3 rubygems

Version Path
json-schema-ouidou-2.9.1 lib/json-schema/attributes/formats/date.rb
json-schema-ouidou-2.9.0 lib/json-schema/attributes/formats/date.rb
json-schema-3.0.0 lib/json-schema/attributes/formats/date.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/bundler/gems/json-schema-2253a5ee6679/lib/json-schema/attributes/formats/date.rb
mountapi-0.11.1 vendor/json-schema/lib/json-schema/attributes/formats/date.rb
json-schema-2.8.1 lib/json-schema/attributes/formats/date.rb