Skip to content

Commit

Permalink
fix issue #1272
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Jun 1, 2021
1 parent db94346 commit 1c09846
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
11 changes: 1 addition & 10 deletions util/gvalid/gvalid_validator_check_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,7 @@ func (v *Validator) doCheckBuildInRules(
if v, ok := value.(apiTime); ok {
return !v.IsZero(), nil
}
// Standard date string, which must contain char '-' or '.'.
if _, err := gtime.StrToTime(valueStr); err == nil {
match = true
break
}
// Date that not contains char '-' or '.'.
if _, err := gtime.StrToTime(valueStr, "Ymd"); err == nil {
match = true
break
}
match = gregex.IsMatchString(`\d{4}[\.\-\_/]{0,1}\d{2}[\.\-\_/]{0,1}\d{2}`, valueStr)

// Date rule with specified format.
case "date-format":
Expand Down
7 changes: 5 additions & 2 deletions util/gvalid/gvalid_z_unit_basic_all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,23 @@ func Test_Date(t *testing.T) {
val5 := "2010.11.01"
val6 := "2010/11/01"
val7 := "2010=11=01"
val8 := "123"
err1 := gvalid.CheckValue(context.TODO(), val1, rule, nil)
err2 := gvalid.CheckValue(context.TODO(), val2, rule, nil)
err3 := gvalid.CheckValue(context.TODO(), val3, rule, nil)
err4 := gvalid.CheckValue(context.TODO(), val4, rule, nil)
err5 := gvalid.CheckValue(context.TODO(), val5, rule, nil)
err6 := gvalid.CheckValue(context.TODO(), val6, rule, nil)
err7 := gvalid.CheckValue(context.TODO(), val7, rule, nil)
t.Assert(err1, nil)
t.Assert(err2, nil)
err8 := gvalid.CheckValue(context.TODO(), val8, rule, nil)
t.AssertNE(err1, nil)
t.AssertNE(err2, nil)
t.Assert(err3, nil)
t.Assert(err4, nil)
t.Assert(err5, nil)
t.Assert(err6, nil)
t.AssertNE(err7, nil)
t.AssertNE(err8, nil)
})
}

Expand Down

0 comments on commit 1c09846

Please sign in to comment.