'Divide timespan in JavaScript

I have to recreate some logic from Kusto query language in JS and I'm struggling with duration division. How can I get quotient from two durations, like this :

One can divide two timespan values to get their quotient. For example, 1d / 5h gives 4.8. This gives one the ability to express any timespan value as a multiple of another timespan value. For example, to express an hour in seconds, simply divide 1h by 1s: 1h / 1s (with the obvious result, 3600).

(taken from https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/datetime-timespan-arithmetic)

I'm using date-fns, but I'm flexible with libraries.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source