kataras/iris · error · ErrParseKitchenTimeColon

parse kitchen time: missing ':' character

Error message

parse kitchen time: missing ':' character

What it means

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.

Source

Thrown at x/jsonx/kitchen_time.go:16

package jsonx

import (
	"fmt"
	"strconv"
	"strings"
	"time"
)

// KitchenTimeLayout represents the "3:04 PM" Go time format, similar to time.Kitchen.
const KitchenTimeLayout = "3:04 PM"

// KitchenTime holds a json "3:04 PM" time.
type KitchenTime time.Time

var ErrParseKitchenTimeColon = fmt.Errorf("parse kitchen time: missing ':' character")

func parseKitchenTime(s string) (KitchenTime, error) {
	// Remove any second,millisecond variable (probably given by postgres 00:00:00.000000).
	// required(00:00)remove(:00.000000)

	firstIndex := strings.IndexByte(s, ':')
	if firstIndex == -1 {
		return KitchenTime{}, ErrParseKitchenTimeColon
	} else {
		nextIndex := strings.LastIndexByte(s, ':')
		spaceIdx := strings.LastIndexByte(s, ' ')
		if nextIndex > firstIndex && spaceIdx > 0 {
			tmp := s[0:nextIndex]
			s = tmp + s[spaceIdx:]
		}
	}

	tt, err := time.Parse(KitchenTimeLayout, s)

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Send/parse times in the "3:04 PM" format, e.g. "10:30 AM".
  2. Normalize input first: insert the missing colon ("1030 AM" -> "10:30 AM") before calling ParseKitchenTime.
  3. Use errors.Is(err, jsonx.ErrParseKitchenTimeColon) to detect this case and return a friendly validation message to the user.

Example fix

// before
time, err := jsonx.ParseKitchenTime("1030 AM") // ErrParseKitchenTimeColon
// after
time, err := jsonx.ParseKitchenTime("10:30 AM")
Defensive patterns

Strategy: validation

Validate before calling

var kitchenRe = regexp.MustCompile(`^\d{1,2}:\d{2}\s*(AM|PM)$`)
func isKitchenFormat(s string) bool { return kitchenRe.MatchString(strings.TrimSpace(s)) }

Try / catch

t, err := jsonx.ParseKitchenTime(s)
if err != nil {
	if errors.Is(err, jsonx.ErrParseKitchenTimeColon) {
		return fmt.Errorf("%q is not a valid time like \"10:30 AM\"", s)
	}
	return err
}

Prevention

When it happens

Trigger: 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.

Common situations: JSON payloads where users type times without colons; form inputs with custom masks; database values formatted differently than expected; localization stripping separators.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/298814901e407d5e. Report an issue: GitHub.