Skip to content
This repository has been archived by the owner on Apr 10, 2022. It is now read-only.
/ valid-date Public archive

Adds a String#valid_date? method for use in combination with the Rails String#to_date method. Using to_date on a string without a valid date in it throws an exception. Adding the valid_date? method allows checking against a valid date before attempting to performing the conversion.

License

Notifications You must be signed in to change notification settings

pbyrne/valid-date

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Adds String#valid_date? and String#valid_time? methods to add utility to the Rails String#to_date and String#to_time methods. Determines whether the string contains a valid date or time, to check before converting to a date and avoiding an exception.

Examples:

    "2008-01-01".valid_date?          #=> true
    "20080101".valid_date?            #=> true
    "0000-00-00".valid_date?          #=> false
    "".valid_date?                    #=> nil
    
    "2008-01-01".valid_time?          #=> true
    "20080101".valid_time?            #=> true
    "2008-01-01 12:00".valid_time     #=> true
    "2008-01-01 52:99".valid_time     #=> false
    "0000-00-00".valid_time?          #=> false
    "".valid_time?                    #=> nil
    
    

This gem is released under a broad open-source license. See LICENSE for more details.

About

Adds a String#valid_date? method for use in combination with the Rails String#to_date method. Using to_date on a string without a valid date in it throws an exception. Adding the valid_date? method allows checking against a valid date before attempting to performing the conversion.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages