def date(attr, metadata={})
      add_attribute(attr, :date, metadata)
      define_method("#{attr}=") do |arg|
        v = case arg
        when Date then arg
        when Time, DateTime then arg.to_date
        when String then Date.parse(arg)
        when Hash
          args = Util.extract_values(arg, :year, :month, :day)
          args.present? ? Date.new(*args.map(&:to_i)) : nil
        when nil then nil
        else raise ArgumentError.new("can't convert #{arg.class} to Date")
        end
        instance_variable_set("@#{attr}", v)
      end
    end
def date(attr, metadata={})
      add_attribute(attr, :date, metadata)
      define_method("#{attr}=") do |arg|
        v = case arg
        when Date then arg
        when Time, DateTime then arg.to_date
        when String then Date.parse(arg)
        when Hash
          args = Util.extract_values(arg, :year, :month, :day)
          args.present? ? Date.new(*args.map(&:to_i)) : nil
        when nil then nil
        else raise ArgumentError.new("can't convert #{arg.class} to Date")
        end
        instance_variable_set("@#{attr}", v)
      end
    end
Defines a date attribute

 @param [Symbol] attr The name of the attribute
 @param [Hash{Symbol => Object}] metadata The metadata for the attribute