Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
abitdodgy opened this issue Apr 25, 2013 · 5 comments
Open

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

abitdodgy opened this issue Apr 25, 2013 · 5 comments

Comments

@abitdodgy
Copy link

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
Copy link
Member

txus commented Sep 19, 2013

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

@Skulli
Copy link

Skulli commented Feb 25, 2016

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
Copy link
Author

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

@drakmail
Copy link

drakmail commented Jun 7, 2016

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants