@@ -10835,3 +10835,44 @@ func TestDatetimeValidation(t *testing.T) {
1083510835 _ = validate .Var (2 , "datetime" )
1083610836 }, "Bad field type int" )
1083710837}
10838+
10839+ func TestTimeZoneValidation (t * testing.T ) {
10840+ tests := []struct {
10841+ value string `validate:"timezone"`
10842+ tag string
10843+ expected bool
10844+ }{
10845+ // systems may have different time zone database, some systems time zone are case insensitive
10846+ {"America/New_York" , `timezone` , true },
10847+ {"UTC" , `timezone` , true },
10848+ {"" , `timezone` , false },
10849+ {"Local" , `timezone` , false },
10850+ {"Unknown" , `timezone` , false },
10851+ }
10852+
10853+ validate := New ()
10854+
10855+ for i , test := range tests {
10856+
10857+ errs := validate .Var (test .value , test .tag )
10858+
10859+ if test .expected {
10860+ if ! IsEqual (errs , nil ) {
10861+ t .Fatalf ("Index: %d time zone failed Error: %s" , i , errs )
10862+ }
10863+ } else {
10864+ if IsEqual (errs , nil ) {
10865+ t .Fatalf ("Index: %d time zone failed Error: %s" , i , errs )
10866+ } else {
10867+ val := getError (errs , "" , "" )
10868+ if val .Tag () != "timezone" {
10869+ t .Fatalf ("Index: %d time zone failed Error: %s" , i , errs )
10870+ }
10871+ }
10872+ }
10873+ }
10874+
10875+ PanicMatches (t , func () {
10876+ _ = validate .Var (2 , "timezone" )
10877+ }, "Bad field type int" )
10878+ }
0 commit comments