v0.0.586
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m33s

This commit is contained in:
Mike Schwörer 2025-07-04 13:56:53 +02:00
parent 09932046f8
commit b23a444aa2
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 28 additions and 5 deletions

View File

@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.585"
const GoextVersion = "0.0.586"
const GoextVersionTimestamp = "2025-07-04T11:46:00+0200"
const GoextVersionTimestamp = "2025-07-04T13:56:53+0200"

View File

@ -148,12 +148,16 @@ func Avg(v ...time.Time) time.Time {
return time.Time{}
}
var sum int64
t0 := v[0].UnixNano()
var dsum int64
for _, t := range v {
sum += t.UnixNano()
dsum += t.UnixNano() - t0
}
return time.Unix(0, sum/int64(len(v)))
tAvg := t0 + (dsum / int64(len(v)))
return time.Unix(0, tAvg)
}
func Median(v ...time.Time) time.Time {

View File

@ -242,6 +242,25 @@ func TestAvg_MultipleValues(t *testing.T) {
}
}
func TestAvg_ManyValues(t *testing.T) {
t1 := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC)
t2 := time.Date(2022, 1, 2, 0, 0, 0, 0, time.UTC)
t3 := time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC)
t4 := time.Date(2022, 1, 4, 0, 0, 0, 0, time.UTC)
t5 := time.Date(2022, 1, 5, 0, 0, 0, 0, time.UTC)
t6 := time.Date(2022, 1, 6, 0, 0, 0, 0, time.UTC)
t7 := time.Date(2022, 1, 7, 0, 0, 0, 0, time.UTC)
t8 := time.Date(2022, 1, 8, 0, 0, 0, 0, time.UTC)
t9 := time.Date(2022, 1, 9, 0, 0, 0, 0, time.UTC)
expected := time.Date(2022, 1, 5, 0, 0, 0, 0, time.UTC)
result := Avg(t1, t2, t3, t4, t5, t6, t7, t8, t9)
if !result.Equal(expected) {
t.Errorf("Expected %v but got %v", expected, result)
}
}
func TestAvg_TwoValues(t *testing.T) {
t1 := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC)
t2 := time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC)