Skip to content

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

Open

Description

@abitdodgy

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

Activity

  1. txus commented on Sep 19, 2013

    @txus
    Member

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

  2. Skulli commented on Feb 25, 2016

    @Skulli

    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.

  3. abitdodgy commented on Feb 25, 2016

    @abitdodgy
    Author

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

  4. drakmail commented on Jun 7, 2016

    @drakmail

    @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.

  5. SirRawlins commented on Nov 9, 2016

    @SirRawlins

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions