Following the recent proposals and work done around the new `Duration` API, I wanted to propose having a function available for converting a `Duration` into a specific time unit, returning a float value.
I see this function being useful where in your system you want to work with durations, but on inputs and outputs, you are required to convert this duration into a more plain value. The examples I can think of are 1) having an Ecto custom type that loads a value in seconds (or another unit) from the database, converting it into a duration using `Duration.new!(second: value)` and dumps a duration again into a value in seconds by calling `Duration.to_float(duration, :second)` and 2) transforming a duration into a plain number in Phoenix HTML inputs.
Examples of similar APIs I could find are in the
JavaScript Temporal.Duration API or
Ruby ActiveSupport::Duration.
One challenge we may encounter when implementing this function is calculating, for example, how many seconds there are in a year. For this, I think we can rely on the Calendar APIs?
Thoughts?