refactored contact birth date validator

This commit is contained in:
dinsmol 2021-09-10 12:06:30 +03:00
parent e345abc2fc
commit 68b9ff0c71

View file

@ -8,11 +8,7 @@ class Contact::Ident::BirthDateValidator < ActiveModel::Validator
def birth_date_wrong?(record) def birth_date_wrong?(record)
return unless record.birthday? return unless record.birthday?
begin return true if birth_date_format_wrong?(record.code)
Date.parse(record.code)
rescue ArgumentError
return true
end
contact_ident_date = Date.parse(record.code) contact_ident_date = Date.parse(record.code)
date_from = Time.zone.today - 150.years date_from = Time.zone.today - 150.years
@ -22,4 +18,11 @@ class Contact::Ident::BirthDateValidator < ActiveModel::Validator
true true
end end
def birth_date_format_wrong?(date)
Date.parse(date)
false
rescue ArgumentError
true
end
end end