It seems that ActiveRecord and Ruby’s Time object doesn’t play nice with times that are over 24:00. However my database has a lot of those, as they represent a time after midnight but considered to be on the same day. This is a design decision of my data provider:
Note: Trips that span multiple dates will have stop times greater than
24:00:00. For example, if a trip begins at 10:30:00 p.m. and ends at
2:15:00 a.m. on the following day, the stop times would be 22:30:00
and 26:15:00. Entering those stop times as 22:30:00 and 02:15:00 would
not produce the desired results.
How do I deactivate this “validation” of my Time objects? It was suggested that I write my time field as a varchar within the MySQL query but I’m looking for a solution that doesn’t make the database intervene.
UPDATE: Regarding the relevance of keeping the > 24:00 format, querying and asc ordering all the stop_times for a stop using that format would return something like: 23:45, 23:54, 24:35, 24:55, 25:15, which is the actual order in which the next buses are coming.
Whereas going the other way would return: 0:35, 0:55, 1:15, 23:45, 23:54 (this is wrong, the first 3 stop_times are supposed to be sorted after the last 3).
Although @Tilo is right that this is probably not the best time format there is, I had to stick to them and so ended up using raw SQL to convert the time column into a string: