-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_time.go
71 lines (66 loc) · 1.73 KB
/
spec_time.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
package vd
import (
"time"
)
type TimeSpec struct {
Name string
Path string
AllowZero bool
BeforeIt time.Time
AfterIt time.Time
BeforeOrEqualIt time.Time
AfterOrEqualIt time.Time
}
func (r *Rule) Time(v time.Time, spec TimeSpec) {
if r.Fail {return}
if spec.AllowZero == false && v.IsZero() {
r.Break(r.Format.TimeNotAllowZero(spec.Name, spec.Path), spec.Path)
return
}
if spec.CheckBeforeIt(v, r) { return }
if spec.CheckAfterIt(v, r) { return }
if spec.CheckBeforeOrEqualIt(v, r) {return}
if spec.CheckAfterOrEqualIt(v, r) {return}
}
func (spec TimeSpec) CheckBeforeIt(v time.Time, r *Rule) (fail bool) {
if spec.BeforeIt.IsZero() {
return false
}
if v.Before(spec.BeforeIt) == false {
r.Break(r.Format.TimeBeforeIt(spec.Name, spec.Path, v, spec.BeforeIt), spec.Path)
}
return r.Fail
}
func (spec TimeSpec) CheckAfterIt(v time.Time, r *Rule) (fail bool) {
if spec.AfterIt.IsZero() {
return false
}
if v.After(spec.AfterIt) == false {
r.Break(r.Format.TimeAfterIt(spec.Name, spec.Path, v, spec.AfterIt), spec.Path)
}
return r.Fail
}
func (spec TimeSpec) CheckBeforeOrEqualIt(v time.Time, r *Rule) (fail bool) {
if spec.BeforeOrEqualIt.IsZero() {
return false
}
if spec.BeforeOrEqualIt.Equal(v) {
return false
}
if v.Before(spec.BeforeOrEqualIt) == false {
r.Break(r.Format.TimeBeforeOrEqualIt(spec.Name, spec.Path, v, spec.BeforeOrEqualIt), spec.Path)
}
return r.Fail
}
func (spec TimeSpec) CheckAfterOrEqualIt(v time.Time, r *Rule) (fail bool) {
if spec.AfterOrEqualIt.IsZero() {
return false
}
if spec.AfterOrEqualIt.Equal(v) {
return false
}
if v.After(spec.AfterOrEqualIt) == false {
r.Break(r.Format.TimeAfterOrEqualIt(spec.Name, spec.Path, v, spec.AfterOrEqualIt), spec.Path)
}
return r.Fail
}