Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/valid-date.rb
Instance Method Summary collapse
-
#valid_date? ⇒ Boolean
Determines whether the string contains a valid date for use with the Rails String#to_date method.
-
#valid_time? ⇒ Boolean
Determines whether the string contains a valid time for use with the Rails String#to_time method.
Instance Method Details
#valid_date? ⇒ Boolean
Determines whether the string contains a valid date for use with the Rails String#to_date method.
"2008-01-01".valid_date? #=> true
"20080101".valid_date? #=> true
"0000-00-00".valid_date? #=> false
"".valid_date? #=> nil
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/valid-date.rb', line 13 def valid_date? unless self == '' begin date = self.to_date result = true rescue Exception => e result = false end end result end |
#valid_time? ⇒ Boolean
Determines whether the string contains a valid time for use with the Rails String#to_time method.
"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
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/valid-date.rb', line 36 def valid_time? unless self == '' begin date = self.to_time result = true rescue Exception => e result = false end end result end |