Let’s say I want to get the fractional hours elapsed between two times. I often have code that looks something like
function hours_elapsed(start, stop)
millis = (stop - start).value
return millis / (1000 * 60 * 60)
This seems nasty for two reasons:
Trusting start - stop to return a Millisecond and not some other period type seems dangerous. Maybe start and stop are some other datetime-like type where subtraction returns a Second, not a Millisecond.
The above snippet is quite a mouthful.
What’s the preferred way to convert some elapsed time to a fractional number of time units?