I understand this from ActiveSupport::Duration
(Rails 4.2.4 + ruby 2.2.1):
main > (1.month + 2.days).parts
[[:months, 1], [:days, 2]]
I don't understand this though:
main > (1.hour + 35.minutes).parts
[[:seconds, 3600], [:seconds, 2100]]
Does ActiveSupport::Duration
not handle hours and seconds the way it handles months and days? The docs on ActiveSupport::Duration
are quite sparse (I can't seem to find better docs).
My main goal is to store a duration (hours and minutes) in a Rails model. Should I forget about ActiveSupport::Duration
and just store seconds and then do my own calculations?
ActiveSupport handles months and days (and years) separately from hours, minutes and seconds.
This is because a duration of one hour (or 23 minutes) is always an exact number of seconds. A month on the other hand is a varying number of days and a day can have either 23, 24, or 25 hours depending on daylight savings changes.
It sounds like you don't need this functionality, in which case storing a number of seconds is probably simpler.