forked from pengux/check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datetime.go
31 lines (24 loc) · 827 Bytes
/
datetime.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
package check
import "time"
// Before check if a time in Value is before the time in Constraint
type Before struct {
Constraint time.Time
}
// Validate check if a time in Value is before the time in Constraint
func (validator Before) Validate(v interface{}) Error {
if !v.(time.Time).Before(validator.Constraint) {
return NewValidationError("before", v.(time.Time).String(), validator.Constraint.String())
}
return nil
}
// After check if a time in Value is before the time in Constraint
type After struct {
Constraint time.Time
}
// Validate check if a time in Value is after the time in Constraint
func (validator After) Validate(v interface{}) Error {
if !v.(time.Time).After(validator.Constraint) {
return NewValidationError("after", v.(time.Time).String(), validator.Constraint.String())
}
return nil
}