From 61ff1d5941d8e8f672b54fc082b148f0b2379d54 Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Sat, 20 Jul 2024 02:14:20 +0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20utility=20functions=20for=20c?= =?UTF-8?q?alculating=20min,=20max,=20and=20average=20durations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/time.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 utils/time.go diff --git a/utils/time.go b/utils/time.go new file mode 100644 index 0000000..222e4cd --- /dev/null +++ b/utils/time.go @@ -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)) +} \ No newline at end of file