This project is archived and is in readonly mode.
Numeric::Time is not consistent, giving confusing results to Duration#inspect
-
Amiel Martin
another idea is to write a method in ActiveSupport::Duration that "normalizes" internal data.
# example >> 65.seconds => 65 seconds >> 65.seconds.parts => [[:seconds, 65]] >> 65.seconds.normalize => 1 minute and 5 seconds >> 65.seconds.normalize.parts => [[:minutes, 1], [:seconds, 5]]any thoughts?
-
Amiel Martin
- Title changed from Numeric::Time is not consistent giving confusing results to Duration#inspect to Numeric::Time is not consistent, giving confusing results to Duration#inspect
-
Amiel Martin
or, maybe this would be better
>> 5.seconds + 1.minute => 65 seconds >> _.humanize => "1 minute and 5 seconds"I'm happy to implement any of the above, the only question is which.
-
Levin Alexander
I think the rationale is that days and months are not constant, their length depends on the context (1.month could stand for 30 or 31 days, a day might get an extra hour on DST)
Hours and minutes on the other hand have a constant length (1.hour is always exactly equal to 3600.seconds) so it makes sense to lump them together to make calculations faster and simpler.
-
Amiel Martin
So, what would be the best action here? I'd love to contribute, and I think having a way to output a duration in human readable form would be a good feature.
