Handle invalid time for Rails 3

This will need to be ported into master too.