mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
reverted parser method as not working with raised exception
This commit is contained in:
parent
2284844426
commit
b019f87625
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user