wiki/recent.go
Peter Stuifzand a318361b8a
All checks were successful
the build was successful
Copy changes
2019-03-03 08:33:55 +01:00

48 lines
641 B
Go

package main
import (
"time"
)
func combine(x, y Change) Change {
x.Count++
if x.Body == "" {
x.Body = y.Body
} else {
x.Body += " " + y.Body
}
x.EndDate = y.Date
return x
}
func changeEqual(x, y Change) bool {
return x.Page == y.Page && x.Date.Truncate(24*time.Hour) == y.Date.Truncate(24*time.Hour)
}
func groupRecentChanges(changes []Change) int {
if len(changes) <= 1 {
return 0
}
f := len(changes) - 1
i := f - 1
for {
if changeEqual(changes[f], changes[i]) {
changes[f] = combine(changes[f], changes[i])
} else {
f--
changes[f] = changes[i]
}
if i <= 0 {
break
}
i--
}
return f
}