codegram / date_validator

A simple, ORM agnostic, Ruby >=2.2 compatible date validator for Rails, based on ActiveModel.
http://thoughts.codegram.com/date-validation-with-rails-3
MIT License
496 stars 82 forks source link

Add way to check is a string is a valid date #38

Open abitdodgy opened 11 years ago

abitdodgy commented 11 years ago

Is it possible to add a way just to check if a given string is a valid date?

validates :release_date, date: true

@product.release_date = "1/1/ab"
@product.should_not be_valid

Failure/Error: @product.should_not be_valid
       expected #<Product id: nil, name: "Assassin's Creed", properties: {"platform"=>"PS3", "release_date"=>"31/12/ab"}> not to be valid
txus commented 11 years ago

@abitdodgy this particular case is not handled :) Care to give it a try in a PR?

Skulli commented 8 years ago

Yea would like that too. Using that gem in like form-objects where the input is a string, the gem currently wont recognize a correct string representation of a date.

abitdodgy commented 8 years ago

@txus Sorry, I missed your comment. I'll give this a bash, more than two years later :laughing:

drakmail commented 8 years ago

@Skulli in case of usage Reform form objects it's possible to include Coercion module from virtus gem to correctly handle string representation of a date.

SirRawlins commented 7 years ago

@drakmail's approach appears to work nicely, for more details checkout the Reform docs. http://trailblazer.to/gems/reform/options.html#coercion