2
0
mirror of https://github.com/edouardparis/lntop synced 2024-11-06 03:20:21 +00:00
lntop/ui/models/sort.go
2021-08-11 18:06:31 +03:00

73 lines
913 B
Go

package models
import (
"strings"
"time"
)
type Order int
const (
Asc Order = iota
Desc
)
func IntSort(a, b int, o Order) bool {
if o == Asc {
return a < b
}
return a > b
}
func Int32Sort(a, b int32, o Order) bool {
if o == Asc {
return a < b
}
return a > b
}
func Int64Sort(a, b int64, o Order) bool {
if o == Asc {
return a < b
}
return a > b
}
func UInt64Sort(a, b uint64, o Order) bool {
if o == Asc {
return a < b
}
return a > b
}
func DateSort(a, b *time.Time, o Order) bool {
if o == Desc {
if a == nil || b == nil {
return b == nil
}
return a.After(*b)
}
if a == nil || b == nil {
return a == nil
}
return a.Before(*b)
}
func StringSort(a, b string, o Order) bool {
result := strings.Compare(a, b)
if o == Asc {
return result < 0
}
return result > 0
}
func BoolSort(a, b bool, o Order) bool {
if o == Asc {
return !a && b
}
return a && !b
}