11module DateOfBirthMethods
22 def date_of_birth = ( string_value )
3+ # If the date is "00/00/0000", set it directly
4+ if string_value == "00/00/0000"
5+ write_attribute ( :date_of_birth , nil )
6+ return
7+ end
8+
39 dob = nil
410 if string_value . is_a? ( String )
511 if matches = string_value . match ( /\A (\d {1,2})\D +(\d {1,2})\D +(\d {4})\z / )
@@ -77,9 +83,8 @@ def form_date_of_birth
7783 end
7884 end
7985
80- # TODO: remove duplicate from RegistrantAbrMethods
8186 def validate_date_of_birth_age
82- if date_of_birth . present?
87+ if date_of_birth . present? && date_of_birth != "00/00/0000"
8388 age_in_years = ( Date . today - date_of_birth ) . to_i / 365
8489 if age_in_years < 13
8590 errors . add ( :date_of_birth , :way_too_young )
@@ -94,8 +99,13 @@ def validate_date_of_birth_age
9499 end
95100 end
96101
97- # TODO: remove duplicate from RegistrantAbrMethods
98102 def validate_date_of_birth
103+ # Skip validation if the date_of_birth is "00/00/0000"
104+ if date_of_birth == "00/00/0000" || date_of_birth . nil?
105+ self [ :date_of_birth ] = nil # Explicitly set it to nil if it's "00/00/0000"
106+ return
107+ end
108+
99109 if date_of_birth_before_type_cast . is_a? ( Date ) || date_of_birth_before_type_cast . is_a? ( Time )
100110 validate_date_of_birth_age
101111 return
0 commit comments