-
Notifications
You must be signed in to change notification settings - Fork 0
/
lessequal.go
51 lines (36 loc) · 886 Bytes
/
lessequal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package path
import (
"time"
"cloud.google.com/go/civil"
)
func LessEqual(obj any, path string, matchStr string) (bool, error) {
return op(obj, path, matchStr, lessEqual)
}
func lessEqual(obj, match any, _ string) bool {
switch objt := obj.(type) {
case int:
return objt <= match.(int)
case int64:
return objt <= match.(int64)
case uint:
return objt <= match.(uint)
case uint64:
return objt <= match.(uint64)
case float32:
return objt <= match.(float32)
case float64:
return objt <= match.(float64)
case string:
return objt <= match.(string)
case bool:
return !objt || objt == match.(bool)
case time.Time:
tm := match.(*timeVal)
trunc := objt.Truncate(tm.precision)
return trunc.Equal(tm.time) || trunc.Before(tm.time)
case civil.Date:
return objt == match.(civil.Date) || objt.Before(match.(civil.Date))
default:
panic(obj)
}
}