{"record":{"id":"e9ac695599c9ba6b","repo":"kataras/iris","slug":"s-w","errorCode":null,"errorMessage":"%s, %w","messagePattern":"%s, %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"context/strconv.go","lineNumber":203,"sourceCode":"\n\treturn result, nil\n}\n\nfunc strParseTime(layout, value string) (time.Time, error) {\n\treturn time.Parse(layout, value)\n}\n\nconst (\n\tsimpleDateLayout1 = \"2006/01/02\"\n\tsimpleDateLayout2 = \"2006-01-02\"\n)\n\nfunc strParseSimpleDate(value string) (time.Time, error) {\n\tt1, err := strParseTime(simpleDateLayout1, value)\n\tif err != nil {\n\t\tt2, err2 := strParseTime(simpleDateLayout2, value)\n\t\tif err2 != nil {\n\t\t\treturn time.Time{}, fmt.Errorf(\"%s, %w\", err.Error(), err2)\n\t\t}\n\n\t\treturn t2, nil\n\t}\n\n\treturn t1, nil\n}\n","sourceCodeStart":185,"sourceCodeEnd":211,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/strconv.go#L185-L211","documentation":"strParseSimpleDate tries two accepted date layouts; if both fail it returns a wrapped error containing both parse failure messages. The error tells you the value did not match either supported simple-date layout.","triggerScenarios":"Calling PostValueSimpleDate on a Context (or indirectly strParseSimpleDate) with a string not matching simpleDateLayout1 or simpleDateLayout2 — e.g. \"2024-01-05T10:00:00Z\", \"01/05/2024\", or an empty value from a missing form field.","commonSituations":"Client sends RFC3339 timestamps instead of a plain date; form field omitted so empty string parsed; locale-formatted dates (\"05/01/2024\"); extra whitespace in the input.","solutions":["Check the library's accepted simple date layouts and format the input accordingly before posting it (e.g. send \"2024-01-05\" style values).","Trim/validate the input; if the value may be empty, check form presence before calling PostValueSimpleDate.","Parse the raw string yourself with time.Parse using the layouts you need, then use the generic PostValue API.","Handle the returned error and return 400 to the client with a message naming the expected format."],"exampleFix":"// before\nv := ctx.PostValueSimpleDate(\"date\") // \"2024-01-05T10:00:00Z\" -> error\n// after\nraw := strings.TrimSpace(ctx.PostValue(\"date\"))\nif len(raw) > 10 { raw = raw[:10] } // keep only YYYY-MM-DD\nd, _ := time.Parse(\"2006-01-02\", raw)","handlingStrategy":"try-catch","validationCode":"raw := strings.TrimSpace(input)\nif _, err := time.Parse(\"2006-01-02\", raw); err != nil {\n    return errors.New(\"date must be in YYYY-MM-DD format\")\n}","typeGuard":null,"tryCatchPattern":"d, err := ctx.PostValueSimpleDate(\"date\")\nif err != nil {\n    http.Error(w, \"expected simple date format\", http.StatusBadRequest)\n    return\n}","preventionTips":["Validate/trim date inputs before calling PostValueSimpleDate","Document the accepted layouts to API clients","Check for empty form values first"],"tags":["date-parsing","input-validation"],"backgroundTag":"date-parse-failed","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}