kataras/iris · error

error parsing offset seconds: %s: %w

Error message

error parsing offset seconds: %s: %w

What it means

While parsing an unconventional '+HH:MM:SS' offset, adjustForUnconventionalOffset converts the seconds field with strconv.Atoi. This error wraps the strconv failure: the seconds portion of the offset was not a plain integer. The offset string is included and the strconv error is wrapped with %w.

Source

Thrown at x/jsonx/iso8601.go:254

	if err != nil {
		return time.Time{}, fmt.Errorf("error parsing offset hours: %s: %w", offset, err)
	}

	if hours > 24 {
		return time.Time{}, fmt.Errorf("invalid offset hours: %d: %s", hours, offset)
	}

	minutes, err := strconv.Atoi(offsetParts[1])
	if err != nil {
		return time.Time{}, fmt.Errorf("error parsing offset minutes: %s: %w", offset, err)
	}
	if minutes > 60 {
		return time.Time{}, fmt.Errorf("invalid offset minutes: %d: %s", minutes, offset)
	}

	seconds, err := strconv.Atoi(offsetParts[2])
	if err != nil {
		return time.Time{}, fmt.Errorf("error parsing offset seconds: %s: %w", offset, err)
	}

	if seconds > 60 {
		return time.Time{}, fmt.Errorf("invalid offset seconds: %d: %s", seconds, offset)
	}

	totalOffset := time.Duration(sign) * (time.Duration(hours)*time.Hour + time.Duration(minutes)*time.Minute + time.Duration(seconds)*time.Second)
	return t.Add(-totalOffset), nil
}

// UnmarshalJSON parses the "b" into ISO8601 time.
func (t *ISO8601) UnmarshalJSON(b []byte) error {
	if len(b) == 0 {
		return nil
	}

	s := strings.Trim(string(b), `"`)
	tt, err := ParseISO8601(s)

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Fix the offset so the seconds field is plain ASCII digits (e.g. '+03:30:00').
  2. Ensure the offset has three complete two-digit numeric fields; regenerate if truncated.
  3. Produce standard RFC3339 timestamps (which need no seconds in the offset) at the source.

Example fix

// before
ParseISO8601("2024-01-02T15:04:05+03:30:0z") // error parsing offset seconds
// after
ParseISO8601("2024-01-02T15:04:05+03:30:00")
Defensive patterns

Strategy: validation

Validate before calling

func offsetSecondsNumeric(ts string) bool {
	i := strings.LastIndexAny(ts, "+-")
	if i < 0 { return false }
	parts := strings.Split(ts[i+1:], ":")
	if len(parts) != 3 { return false }
	_, err := strconv.Atoi(parts[2])
	return err == nil
}

Try / catch

tt, err := jsonx.ParseISO8601(s)
if err != nil {
	if strings.Contains(err.Error(), "error parsing offset seconds") {
		return fmt.Errorf("malformed timestamp %q: %w", s, err)
	}
	return err
}

Prevention

When it happens

Trigger: ParseISO8601 on a timestamp whose offset seconds field contains non-digits, e.g. '+03:30:0z' or a truncated '+03:30:' tail.

Common situations: Hand-edited or truncated timestamps; offsets coming from string-slicing code that drops characters; non-ASCII digits from locale-aware formatting.

Related errors


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