I\'m looking for the best way to use a duration field in a Rails model. I would like the format to be HH:MM:SS (ex: 01:30:23). The database in use is sqlite locally and Postgr
SUM
query over the duration column to produce a grand total. If you use integers, this is easy and fast.Additionally:
ActiveSupport::Duration
by using 123.seconds
(replace 123
with the integer from the database). Use inspect
on the resulting Duration
for nice formatting. (It is not perfect. You may want to write something yourself.)ActiveSupport::Duration
objects, rather than integers. Simply define duration=(new_duration)
and duration
, which internally call read_attribute
/ write_attribute
with integer arguments.