Sha256: 06edc948bd027ae191cb7eaf6164aaac217481e025141a26dd6889932465a1c7

Contents?: true

Size: 498 Bytes

Versions: 2

Compression:

Stored size: 498 Bytes

Contents

module ValidateParams
  class Types
    class Date
      def self.valid?(value)
        value = value.to_s
        return false if !/\d{4}-\d{2}-\d{2}/.match?(value)

        parsed_date = begin
                        ::Date.strptime(value, "%Y-%m-%d")
                      rescue StandardError
                        nil
                      end
        return false if parsed_date.nil?
        return false if parsed_date.year > 9999
        true
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
validate-params-0.6.1 lib/validate_params/types/date.rb
validate-params-0.6.0 lib/validate_params/types/date.rb