-
Notifications
You must be signed in to change notification settings - Fork 4
/
before.go
29 lines (25 loc) · 848 Bytes
/
before.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
package govalidator
import "time"
const (
// Before represents rule name which will be used to find the default error message.
Before = "before"
// BeforeMsg is the default error message format for fields with Before validation rule.
BeforeMsg = "%s should be before %v"
)
// Before checks if given time instant t is before u.
//
// Example:
//
// v := validator.New()
//
// t, _ := time.Parse("2006-01-02", "2009-01-02") // error ignored for simplicity
// u, _ := time.Parse("2006-01-02", "2012-01-01") // error ignored for simplicity
//
// v.Before(t, u, "birth_date", "birth_date should be before 2012-01-01.")
// if v.IsFailed() {
// fmt.Printf("validation errors: %#v\n", v.Errors())
// }
func (v Validator) Before(t, u time.Time, field, msg string) Validator {
v.check(t.Before(u), field, v.msg(Before, msg, field, u))
return v
}