mirror of
https://github.com/taigrr/most-specific-period.git
synced 2026-04-02 03:38:41 -07:00
add changes to changeover code based on unit tests
This commit is contained in:
2
go.mod
2
go.mod
@@ -1,3 +1,3 @@
|
|||||||
module github.com/taigrr/most-specific-period
|
module github.com/taigrr/most-specific-period
|
||||||
|
|
||||||
go 1.17
|
go 1.18
|
||||||
|
|||||||
@@ -11,11 +11,20 @@ func GetChangeOvers(periods ...Period) (changeovers []time.Time) {
|
|||||||
timeStamps = append(timeStamps, x.GetEndTime())
|
timeStamps = append(timeStamps, x.GetEndTime())
|
||||||
timeStamps = append(timeStamps, x.GetStartTime())
|
timeStamps = append(timeStamps, x.GetStartTime())
|
||||||
}
|
}
|
||||||
|
if len(timeStamps) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
sort.Slice(timeStamps, func(i, j int) bool {
|
sort.Slice(timeStamps, func(i, j int) bool {
|
||||||
return timeStamps[i].Before(timeStamps[j])
|
return timeStamps[i].Before(timeStamps[j])
|
||||||
})
|
})
|
||||||
|
// timeStamps is sorted, so this will always result in an unused time
|
||||||
|
// struct, as it's before the first
|
||||||
|
previousTs := timeStamps[0].Add(-10 * time.Nanosecond)
|
||||||
for _, ts := range timeStamps {
|
for _, ts := range timeStamps {
|
||||||
|
if ts.Equal(previousTs) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
previousTs = ts
|
||||||
before := ts.Add(-1 * time.Nanosecond)
|
before := ts.Add(-1 * time.Nanosecond)
|
||||||
after := ts.Add(1 * time.Nanosecond)
|
after := ts.Add(1 * time.Nanosecond)
|
||||||
from, _ := MostSpecificPeriod(before, periods...)
|
from, _ := MostSpecificPeriod(before, periods...)
|
||||||
|
|||||||
Reference in New Issue
Block a user