Comparing 2 time.Duration values in go with math.Min errs :
cannot use someTime (type time.Duration) as type float64 in argument to math.Min
I could use an if else statement to get the min duration, but is there a native min function for getting the min duration?
There's nothing in the standard library, but it's simple to write yourself.
func minDuration(a, b time.Duration) time.Duration {
if a <= b { return a }
return b
}
[update 2023]
You can use the builtin min since go release 1.21. Now it's as simple as min(a, b) where a and b are time.Duration values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With