-
Notifications
You must be signed in to change notification settings - Fork 3
/
lt.go
58 lines (50 loc) · 1.09 KB
/
lt.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
52
53
54
55
56
57
58
package connor
import (
"fmt"
"time"
"github.com/SierraSoftworks/connor/internal/numbers"
)
func init() {
Register(&LessOperator{})
}
// LessOperator does value comparisons to determine whether one
// value is strictly less than another.
type LessOperator struct {
}
func (o *LessOperator) Name() string {
return "lt"
}
func (o *LessOperator) Evaluate(condition, data interface{}) (bool, error) {
switch cn := numbers.TryUpcast(condition).(type) {
case string:
switch dn := data.(type) {
case string:
return dn < cn, nil
}
return false, nil
case float64:
switch dn := numbers.TryUpcast(data).(type) {
case float64:
return dn < cn, nil
case int64:
return float64(dn) < cn, nil
}
return false, nil
case int64:
switch dn := numbers.TryUpcast(data).(type) {
case float64:
return dn < float64(cn), nil
case int64:
return dn < cn, nil
}
return false, nil
case time.Time:
switch dn := data.(type) {
case time.Time:
return dn.Before(cn), nil
}
return false, nil
default:
return false, fmt.Errorf("unknown comparison type '%#v'", condition)
}
}