mirror of
https://github.com/kopia/kopia.git
synced 2026-05-14 01:37:07 -04:00
fix(general): Delete duplicates in time of day array within policies (#3484)
Test in #3535
This commit is contained in:
committed by
GitHub
parent
fc640a98e4
commit
bb8b33a289
@@ -1,10 +1,11 @@
|
||||
package policy
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -45,14 +46,17 @@ func (t TimeOfDay) String() string {
|
||||
|
||||
// SortAndDedupeTimesOfDay sorts the slice of times of day and removes duplicates.
|
||||
func SortAndDedupeTimesOfDay(tod []TimeOfDay) []TimeOfDay {
|
||||
sort.Slice(tod, func(i, j int) bool {
|
||||
if a, b := tod[i].Hour, tod[j].Hour; a != b {
|
||||
return a < b
|
||||
slices.SortFunc(tod, func(a, b TimeOfDay) int {
|
||||
if n := cmp.Compare(a.Hour, b.Hour); n != 0 {
|
||||
return n
|
||||
}
|
||||
return tod[i].Minute < tod[j].Minute
|
||||
|
||||
// If hours are equal sort by minute
|
||||
return cmp.Compare(a.Minute, b.Minute)
|
||||
})
|
||||
|
||||
return tod
|
||||
// Remove subsequent duplicates
|
||||
return slices.Compact[[]TimeOfDay, TimeOfDay](tod)
|
||||
}
|
||||
|
||||
// SchedulingPolicy describes policy for scheduling snapshots.
|
||||
|
||||
Reference in New Issue
Block a user