{"record":{"id":"298814901e407d5e","repo":"kataras/iris","slug":"parse-kitchen-time-missing-character","errorCode":null,"errorMessage":"parse kitchen time: missing ':' character","messagePattern":"parse kitchen time: missing ':' character","errorType":"validation","errorClass":"ErrParseKitchenTimeColon","httpStatus":null,"severity":"error","filePath":"x/jsonx/kitchen_time.go","lineNumber":16,"sourceCode":"package jsonx\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n)\n\n// KitchenTimeLayout represents the \"3:04 PM\" Go time format, similar to time.Kitchen.\nconst KitchenTimeLayout = \"3:04 PM\"\n\n// KitchenTime holds a json \"3:04 PM\" time.\ntype KitchenTime time.Time\n\nvar ErrParseKitchenTimeColon = fmt.Errorf(\"parse kitchen time: missing ':' character\")\n\nfunc parseKitchenTime(s string) (KitchenTime, error) {\n\t// Remove any second,millisecond variable (probably given by postgres 00:00:00.000000).\n\t// required(00:00)remove(:00.000000)\n\n\tfirstIndex := strings.IndexByte(s, ':')\n\tif firstIndex == -1 {\n\t\treturn KitchenTime{}, ErrParseKitchenTimeColon\n\t} else {\n\t\tnextIndex := strings.LastIndexByte(s, ':')\n\t\tspaceIdx := strings.LastIndexByte(s, ' ')\n\t\tif nextIndex > firstIndex && spaceIdx > 0 {\n\t\t\ttmp := s[0:nextIndex]\n\t\t\ts = tmp + s[spaceIdx:]\n\t\t}\n\t}\n\n\ttt, err := time.Parse(KitchenTimeLayout, s)","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/jsonx/kitchen_time.go#L1-L34","documentation":"parseKitchenTime expects a time-of-day string in the \"3:04 PM\" layout (e.g. \"10:30 AM\") and first checks that the input contains a ':' character. ErrParseKitchenTimeColon is returned when no colon is present, so the string cannot be a valid hour:minute kitchen time. It is exported so callers can compare with errors.Is.","triggerScenarios":"Calling ParseKitchenTime with strings lacking a colon: \"1030 AM\", \"noon\", \"10 AM\", an empty-but-non-null numeric string from JSON like \"1030\", or a postgres time value pre-processed in a way that removed the colon.","commonSituations":"JSON payloads where users type times without colons; form inputs with custom masks; database values formatted differently than expected; localization stripping separators.","solutions":["Send/parse times in the \"3:04 PM\" format, e.g. \"10:30 AM\".","Normalize input first: insert the missing colon (\"1030 AM\" -> \"10:30 AM\") before calling ParseKitchenTime.","Use errors.Is(err, jsonx.ErrParseKitchenTimeColon) to detect this case and return a friendly validation message to the user."],"exampleFix":"// before\ntime, err := jsonx.ParseKitchenTime(\"1030 AM\") // ErrParseKitchenTimeColon\n// after\ntime, err := jsonx.ParseKitchenTime(\"10:30 AM\")","handlingStrategy":"validation","validationCode":"var kitchenRe = regexp.MustCompile(`^\\d{1,2}:\\d{2}\\s*(AM|PM)$`)\nfunc isKitchenFormat(s string) bool { return kitchenRe.MatchString(strings.TrimSpace(s)) }","typeGuard":null,"tryCatchPattern":"t, err := jsonx.ParseKitchenTime(s)\nif err != nil {\n\tif errors.Is(err, jsonx.ErrParseKitchenTimeColon) {\n\t\treturn fmt.Errorf(\"%q is not a valid time like \\\"10:30 AM\\\"\", s)\n\t}\n\treturn err\n}","preventionTips":["Validate user input against the 3:04 PM format before calling ParseKitchenTime.","Auto-insert a missing colon (\"1030\" -> \"10:30\") in form handling.","Compare against jsonx.ErrParseKitchenTimeColon with errors.Is for friendly messages."],"tags":["time-parsing","kitchen-time","format-validation","go"],"backgroundTag":"invalid-time-format","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}