validates_date_time Not Ready for Prime Time

Just a warning to those that might be looking to use `validates_date_time` for Rails.

It turns out that it implements its own date and time parsing. This is separate from the current date and time parsing in Rails, which is currently handled by the DB driver. This dual reality is very confusing, and creates two different parsing logics and semantics in your application. I fought for an hour trying to figure out why '2006-1-1' was not a valid date. It was working before this plugin.

Reason? My current database, MySQL knows what '2006-1-1' is and thus was able to parse it. But the plugin doesn't know this format.

I'm not saying that I approve of the fact that the date/time conversion is handled by the database driver. In fact, I know it's not very portable. But this plugin should rely on that behavior, or be much more liberal and understand 2006-1-1, or use any existing Date or Time parsing.

Another odd thing about this plugin is that `validates_date_time` can't handle just '1/1/2006', as it is expecting a time part in there. It doesn't default to midnight.

For the time being, I'd recommend writing your own `validates_datetime` to match what you are expecting. Don't reinvent the wheel. If you need to do date parsing, there are existing options to rely on.

Popular posts from this blog

Lists and arrays in Dart

Converting Array to List in Scala

Null-aware operators in Dart