go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.86k stars 1.32k forks source link

panic: Undefined validation function 'datetime' #687

Open jtbonhomme opened 4 years ago

jtbonhomme commented 4 years ago

Package version eg. v9, v10:

Issue, Question or Enhancement:

Got a panic during validation of a structure with erreur message:

panic: Undefined validation function 'datetime' on field 'CreatedAt' [recovered]
        panic: Undefined validation function 'datetime' on field 'CreatedAt'

The documentation clearly states:

Tag Description
datetime Datetime

Issue #643 suggests to add Golang time format expected. I tried both forms but neither worked.

Code sample, to showcase or reproduce:

type MyRequest struct {
    ...
    CreatedAt time.Time `json:"createdAt" validate:"required,datetime"`
    ... or ...
    CreatedAt time.Time `json:"createdAt" validate:"required,datetime=2006-01-02T15:04:05.999999999Z"`
}

The content of MyRequest.CreatedAt field is : 2020-11-10T20:46:01.0700047Z

cdkini commented 3 years ago

@jtbonhomme any resolution on this? I'm seeing the same issue on go1.14.2 linux/am64 with Ubuntu.

vishal1132 commented 3 years ago

@jtbonhomme Fixed in v10 https://github.com/go-playground/validator/releases/tag/v10.2.0. See the commit https://github.com/go-playground/validator/commit/c68441b7f4748b48ad9a0c9a79d346019730e207#diff-6eda4809e29e9c01c780a30c46947d23b10606dbd948fd00dc5376030cf897c6R2077.

ghost commented 2 years ago

@jtbonhomme any resolution on this? I'm seeing the same issue on go1.14.2 linux/am64 with Ubuntu.

I still seeing the same issue too go1.18

kameshraoyeduvakula commented 11 months ago

any resolution? i am seeing this too.

nodivbyzero commented 4 months ago

Here is the fix:

type MyRequest struct {
    CreatedAt string `json:"createdAt" validate:"required,datetime=2006-01-02T15:04:05.999999999Z"`
}