From e4760126e20d2cb9545b26b51c6b25f217fe2410 Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Sun, 7 Dec 2008 11:06:43 +1100 Subject: [PATCH] allow for a string column being validated as a date/time --- lib/validates_timeliness/validator.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/validates_timeliness/validator.rb b/lib/validates_timeliness/validator.rb index 923b108..e11cf67 100644 --- a/lib/validates_timeliness/validator.rb +++ b/lib/validates_timeliness/validator.rb @@ -9,7 +9,7 @@ module ValidatesTimeliness :time => '%H:%M:%S', :date => '%Y-%m-%d', :datetime => '%Y-%m-%d %H:%M:%S' - } + } attr_reader :configuration, :type @@ -19,10 +19,9 @@ module ValidatesTimeliness @type = @configuration.delete(:type) end - # The main validation method which can be used directly or called through - # the other specific type validation methods. def call(record, attr_name) value = record.send(attr_name) + value = record.class.parse_date_time(value, type, false) if value.is_a?(String) raw_value = raw_value(record, attr_name) return if (raw_value.nil? && configuration[:allow_nil]) || (raw_value.blank? && configuration[:allow_blank])