-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdatefilter.go
95 lines (77 loc) · 1.9 KB
/
datefilter.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package yaormfilter
import (
"reflect"
"time"
"github.com/geoffreybauduin/yaorm/tools"
)
// DateFilter is a filter to operate on date fields
type DateFilter struct {
valuefilterimpl
}
var (
timeType = reflect.TypeOf(time.Time{})
)
// NewDateFilter returns a new DateFilter
func NewDateFilter() ValueFilter {
return &DateFilter{}
}
func (f *DateFilter) getValue(v interface{}) interface{} {
underlyingValue := tools.GetNonPtrValue(v)
// make sure we have a time.Time
if underlyingValue.Kind() != reflect.Struct || underlyingValue.Type() != timeType {
panic("Value in DateFilter is not a time.Time object")
}
return underlyingValue.Interface()
}
// Equals applies an equal filter on Date
func (f *DateFilter) Equals(v interface{}) ValueFilter {
f.equals(f.getValue(v))
return f
}
// NotEquals applies an notEqual filter on Date
func (f *DateFilter) NotEquals(v interface{}) ValueFilter {
f.notEquals(f.getValue(v))
return f
}
// Like is not applicable on Date
func (f *DateFilter) Like(v interface{}) ValueFilter {
return f
}
// Nil applies a nil filter on Date
func (f *DateFilter) Nil(v bool) ValueFilter {
f.nil(v)
return f
}
// In adds a IN filter (not implemented)
func (f *DateFilter) In(values ...interface{}) ValueFilter {
return f
}
// NotIn adds a NOT IN filter (not implemented)
func (f *DateFilter) NotIn(values ...interface{}) ValueFilter {
return f
}
// Lt adds a < filter
func (f *DateFilter) Lt(v interface{}) ValueFilter {
f.lt(f.getValue(v))
return f
}
// Lte adds a <= filter
func (f *DateFilter) Lte(v interface{}) ValueFilter {
f.lte(f.getValue(v))
return f
}
// Gt adds a > filter
func (f *DateFilter) Gt(v interface{}) ValueFilter {
f.gt(f.getValue(v))
return f
}
// Gte adds a > filter
func (f *DateFilter) Gte(v interface{}) ValueFilter {
f.gte(f.getValue(v))
return f
}
// Raw performs a Raw filter
func (f *DateFilter) Raw(s RawFilterFunc) ValueFilter {
f.raw(s)
return f
}