github.com/GuanceCloud/cliutils@v1.1.21/point/sort.go (about) 1 // Unless explicitly stated otherwise all files in this repository are licensed 2 // under the MIT License. 3 // This product includes software developed at Guance Cloud (https://www.guance.com/). 4 // Copyright 2021-present Guance, Inc. 5 6 package point 7 8 import ( 9 "golang.org/x/exp/slices" 10 ) 11 12 // SortByTime sort(ASC) pts according to time. 13 func SortByTime(pts []*Point) { 14 slices.SortFunc(pts, func(l, r *Point) int { 15 diff := l.Time().Sub(r.Time()) 16 // nolint: gocritic 17 if diff == 0 { 18 return 0 19 } else if diff > 0 { 20 return 1 21 } else { 22 return -1 23 } 24 }) 25 }