mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-20 11:11:26 +00:00
✨ Add utility functions for calculating min, max, and average durations
This commit is contained in:
parent
b659d29e50
commit
61ff1d5941
31
utils/time.go
Normal file
31
utils/time.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
func MinDuration(durations ...time.Duration) time.Duration {
|
||||||
|
min := durations[0]
|
||||||
|
for _, d := range durations {
|
||||||
|
if d < min {
|
||||||
|
min = d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return min
|
||||||
|
}
|
||||||
|
|
||||||
|
func MaxDuration(durations ...time.Duration) time.Duration {
|
||||||
|
max := durations[0]
|
||||||
|
for _, d := range durations {
|
||||||
|
if d > max {
|
||||||
|
max = d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
|
||||||
|
func AvgDuration(durations ...time.Duration) time.Duration {
|
||||||
|
total := time.Duration(0)
|
||||||
|
for _, d := range durations {
|
||||||
|
total += d
|
||||||
|
}
|
||||||
|
return total / time.Duration(len(durations))
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user