@@ -9155,4 +9155,42 @@ func TestUppercaseValidation(t *testing.T) {
91559155 PanicMatches (t , func () {
91569156 _ = validate .Var (2 , "uppercase" )
91579157 }, "Bad field type int" )
9158- }
9158+
9159+ }
9160+
9161+ func TestDatetimeValidation (t * testing.T ) {
9162+ tests := []struct {
9163+ value string `validate:"datetime=2006-01-02"`
9164+ tag string
9165+ expected bool
9166+ }{
9167+ {"2008-02-01" , `datetime=2006-01-02` , true },
9168+ {"2008-Feb-01" , `datetime=2006-01-02` , false },
9169+ }
9170+
9171+ validate := New ()
9172+
9173+ for i , test := range tests {
9174+
9175+ errs := validate .Var (test .value , test .tag )
9176+
9177+ if test .expected {
9178+ if ! IsEqual (errs , nil ) {
9179+ t .Fatalf ("Index: %d datetime failed Error: %s" , i , errs )
9180+ }
9181+ } else {
9182+ if IsEqual (errs , nil ) {
9183+ t .Fatalf ("Index: %d datetime failed Error: %s" , i , errs )
9184+ } else {
9185+ val := getError (errs , "" , "" )
9186+ if val .Tag () != "datetime" {
9187+ t .Fatalf ("Index: %d datetime failed Error: %s" , i , errs )
9188+ }
9189+ }
9190+ }
9191+ }
9192+
9193+ PanicMatches (t , func () {
9194+ _ = validate .Var (2 , "datetime" )
9195+ }, "Bad field type int" )
9196+ }
0 commit comments