asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
5.97k stars 554 forks source link

JSON date parser using rfc3339 #390

Open stackchain opened 3 years ago

stackchain commented 3 years ago

I'm using the rfc3339 and it is failing to parse a JSON stringify date that comes from the browser if I parse using time.Parse("2016-12-31T11:00:00.000Z", time.rfc3339) using just GO it works fine, but when I try to use govalidator it fails, I even added a test in validator_test.go and it is passing, but I wasn't able to figure out why it is not working when using the tag notation inside my map (I'm super brand new in golang 2 weeks). Am I missing something?

CheckAt time.Time json:"checkAt" form:"checkAt" query:"checkAt" valid:"rfc3339"

ygj6 commented 3 years ago

https://github.com/asaskevich/govalidator/blob/7a23bdc65eef5f3783e782b436f3065eae3fc72d/validator_test.go#L2124 I added {"2016-12-31T11:00:00.000Z", time.RFC3339, true}, to this test case, also tested pass.

ygj6 commented 3 years ago

@stackchain I did not find any problem when I used the govalidator for verification. Can you provide the test cases you used?

The following is a test case I wrote:

func TestIssue390(t *testing.T)  {
    type TimeModle struct {
        CheckAt string `json:"checkAt"  valid:"rfc3339"`
    }

    timeModle := TimeModle{
        CheckAt:"2016-12-31T11:00:00.000Z",
    }
    result , err :=ValidateStruct(timeModle)
    if err != nil {
        fmt.Println("err is :", err)
    }
    fmt.Println("result value is :", result)
    //output:result value is : true
}
sergeyglazyrindev commented 2 years ago

Hello guys! I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back Link to my repo: create issue there and we'll discuss it.