{"record":{"id":"37b8eaef6aa34fa3","repo":"kataras/iris","slug":"s-w-37b8ea","errorCode":null,"errorMessage":"%s: %w","messagePattern":"%s: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/jsonx/simple_date.go","lineNumber":53,"sourceCode":"//   - \"2024-1-1\"\nfunc ParseSimpleDate(s string) (SimpleDate, error) {\n\tif s == \"\" || s == \"null\" {\n\t\treturn SimpleDate{}, nil\n\t}\n\n\tvar (\n\t\ttt  time.Time\n\t\terr error\n\t)\n\n\ttt, err = time.Parse(SimpleDateLayout, s)\n\tif err != nil {\n\t\t// After v5.0.0-alpha.3 of pgx this is coming as \"1993-1-1\" instead of the stored\n\t\t// value \"1993-01-01\".\n\t\tvar err2 error\n\t\ttt, err2 = time.Parse(simpleDateLayoutPostgres, s)\n\t\tif err2 != nil {\n\t\t\treturn SimpleDate{}, fmt.Errorf(\"%s: %w\", err2.Error(), err)\n\t\t}\n\t}\n\n\treturn SimpleDate(tt), nil\n}\n\n// UnmarshalJSON binds the json \"data\" to \"t\" with the `SimpleDateLayout`.\nfunc (t *SimpleDate) UnmarshalJSON(data []byte) error {\n\tif isNull(data) {\n\t\treturn nil\n\t}\n\n\tdata = trimQuotes(data)\n\tdataStr := string(data)\n\tif len(dataStr) == 0 {\n\t\treturn nil // do not allow empty \"\" on simple dates.\n\t}\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/jsonx/simple_date.go#L35-L71","documentation":"ParseSimpleDate tries \"2006-01-02\" first; if that fails it retries the zero-padded-optional Postgres layout \"2006-1-2\" (pgx v5.0.0-alpha.3+ returns dates like \"1993-1-1\"). If both parses fail, it returns the second error's text followed by the first error, as \"<parse2 error>: <parse1 error>\".","triggerScenarios":"Calling jsonx.ParseSimpleDate (directly or via Scan/UnmarshalJSON paths) with a string that matches neither layout — e.g. \"01/02/1993\", \"1993-01-01 10:00\", \"Jan 2 2006\", or non-date text.","commonSituations":"Reading date strings from CSV/config in a locale format (DD/MM/YYYY); DB columns typed VARCHAR containing datetime strings; passing a full RFC3339 timestamp instead of a bare date.","solutions":["Normalize the input to YYYY-MM-DD before calling ParseSimpleDate.","If it comes from a full timestamp, truncate: t.Format(\"2006-01-02\") first.","Use time.Parse with your custom layout and then convert via jsonx.SimpleDateFromTime(t)."],"exampleFix":"// before\njsonx.ParseSimpleDate(\"01/02/1993\") // error\n// after\nt, _ := time.Parse(\"02/01/2006\", \"01/02/1993\")\nsd := jsonx.SimpleDateFromTime(t)","handlingStrategy":"validation","validationCode":"func isSimpleDateLayout(s string) bool {\n\t_, e1 := time.Parse(\"2006-01-02\", s)\n\t_, e2 := time.Parse(\"2006-1-2\", s)\n\treturn e1 == nil || e2 == nil\n}","typeGuard":"func toSimpleDate(s string) (jsonx.SimpleDate, error) {\n\tfor _, layout := range []string{\"2006-01-02\", \"2006-1-2\", \"02/01/2006\", \"01/02/2006\"} {\n\t\tif t, err := time.Parse(layout, s); err == nil {\n\t\t\treturn jsonx.SimpleDateFromTime(t), nil\n\t\t}\n\t}\n\treturn jsonx.SimpleDate{}, fmt.Errorf(\"unsupported date format: %s\", s)\n}","tryCatchPattern":"sd, err := jsonx.ParseSimpleDate(s)\nif err != nil {\n\t// err text contains both layout failures; log s and fall back to manual layouts\n\treturn fmt.Errorf(\"parse simple date %q: %w\", s, err)\n}","preventionTips":["Normalize all date inputs to YYYY-MM-DD at system boundaries","Truncate timestamps to date before parsing","Keep pgx versions tested; remember pgx v5 zero-padding behavior"],"tags":["go","json","date-parsing","layout","postgres"],"backgroundTag":"invalid-date-format","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}