I’ve got a basic text field where somebody can enter their birthdate.
I’m using a virtual attribute and all is working fine except if a date
is entered between 38 and 68.
Meaning that 01/01/69 will work fine and is interpreted as 01/01/1969
but 01/01/68 gives me a time out of range error:
/usr/local/lib/ruby/1.8/time.rb:184:in local' /usr/local/lib/ruby/1.8/time.rb:184:in
make_time’
/usr/local/lib/ruby/1.8/time.rb:243:in parse' app/models/user.rb:30:in
birthdate_string=’
app/controllers/users_controller.rb:13:in `create’
Everything outside of 38 and 68 is ok. Anyone heard of such a thing?
Here’s my model:
def birthdate_string
birthdate.to_s(:db)
end
def birthdate_string=(birthdate_str)
self.birthdate = Time.parse(birthdate_str)
if self.birthdate.year < 1000
self.birthdate += 1900.years
elsif self.birthdate.year > 2000
self.birthdate -= 100.years
end
end