Rails, PostgreSQL and Time
I just noticed that the mapping between PostgreSQL’s Time Without TimeZone column type maps to Rubys standard Time class. Which gives the following behavior in script/console:
>> t = TimeEntry.find(1) >> t.time => Sat Jan 01 23:00:00 +0100 2000 >> t.time = Time.now => Wed May 09 19:02:07 +0200 2007 >> t.save => true >> t = TimeEntry.find(1) >> t.time => Sat Jan 01 19:02:07 +0100 2000
Am I very anal to find this … sloppy?





June 9th, 2007 at 2:24
No you are not…
Just got bitten by this. This is how: I have a model with attributes timestart and timeend of type :time (time without timezone in PostgreSQL) and one validation that (yes you guessed it) checks whether timestart > h = WorkingHour.find(1) => #”1″, “id”=>”1″, “timeend”=>”15:00:00″, “timestart”=>”08:00:00″, “photographerid”=>”1″}> >> h.valid? => true >> h.timeend => Sat Jan 01 15:00:00 +0200 2000 >> h.timestart => Sat Jan 01 08:00:00 +0200 2000 >> h.timestart = Time.now => Sat Jun 09 03:17:50 +0300 2007 >> h.timeend
=> Sat Jan 01 15:00:00 +0200 2000 >> h.valid? => false >> h.errors.full_messages => ["Starting time must be before ending time"]
This is a bug that needs fixing! What’s the behaviour in MySQL btw?
June 11th, 2007 at 8:18
Interesting bug, I hadn’t thought of that.
I try to stay clear of MySQL, there are too many stories of data corruptiion around.