reverted parser method as not working with raised exception

This commit is contained in:
Adam Meehan 2008-05-14 09:42:34 +10:00
parent 2284844426
commit b019f87625

View File

@ -9,24 +9,6 @@ module ValidatesTimeliness
end
module ClassMethods
def timeliness_date_time_parser(time)
begin
if raw_value.acts_like?(:time) || raw_value.is_a?(Date)
raw_value
else
time_array = ParseDate.parsedate(raw_value)
# checks if date is valid which enforces number of days in a month unlike Time
Date.new(*time_array[0..2])
# checks if time is valid and return object
Time.mktime(*time_array)
end
rescue
raise ValidatesTimeliness::DateTimeInvalid
end
end
def validates_timeliness_of(*attr_names)
configuration = { :on => :save, :allow_nil => false, :allow_blank => false }
@ -47,7 +29,17 @@ module ValidatesTimeliness
column = record.column_for_attribute(attr_name)
begin
time = timeliness_date_time_parser(raw_value)
time = if raw_value.acts_like?(:time) || raw_value.is_a?(Date)
raw_value
else
time_array = ParseDate.parsedate(raw_value)
# checks if date is valid which enforces number of days in a month unlike Time
Date.new(*time_array[0..2])
# checks if time is valid and return object
Time.mktime(*time_array)
end
conversion_method = column.type == :date ? :to_date : :to_time
time = time.send(conversion_method)
@ -75,7 +67,7 @@ module ValidatesTimeliness
end
end
end
rescue ValidatesTimeliness::DateTimeInvalid
rescue
record.send("#{attr_name}=", nil)
record.errors.add(attr_name, "is not a valid #{column.type}")
next