kgretzky/evilginx2 · error

unknown time duration type: '%s', you can use only 'd', 'h',

Error message

unknown time duration type: '%s', you can use only 'd', 'h', 'm' or 's'

What it means

ParseDurationString only recognizes the unit characters 'd', 'h', 'm' and 's'. When it encounters a non-digit character that is not one of these units (after having accumulated a number), it returns this error naming the offending character.

Source

Thrown at core/utils.go:120

						if err != nil {
							return
						}
						switch c {
						case 'd':
							days = val
						case 'h':
							hours = val
						case 'm':
							minutes = val
						case 's':
							seconds = val
						}
					} else {
						err = fmt.Errorf("you can only use time duration types in following order: 'd' > 'h' > 'm' > 's'")
						return
					}
				} else {
					err = fmt.Errorf("unknown time duration type: '%s', you can use only 'd', 'h', 'm' or 's'", string(c))
					return
				}
			} else {
				err = fmt.Errorf("time duration value needs to start with a number")
				return
			}
			s_num = ""
		}
	}
	t_dur = time.Duration(days)*24*time.Hour + time.Duration(hours)*time.Hour + time.Duration(minutes)*time.Minute + time.Duration(seconds)*time.Second
	return
}

func GetDurationString(t_now time.Time, t_expire time.Time) (ret string) {
	var days, hours, minutes, seconds int64
	ret = ""

	if t_expire.After(t_now) {

View on GitHub (pinned to 4c0988a1d9)

Solutions

  1. Use only 'd', 'h', 'm', 's' units: '2h30m' not '2h30min'.
  2. Remove spaces and punctuation from the duration string.
  3. Convert other units first, e.g. weeks to days: '2w' → '14d'.

Example fix

// before
ParseDurationString("2h30min")
// after
ParseDurationString("2h30m")
Defensive patterns

Strategy: validation

Validate before calling

var durRe = regexp.MustCompile(`^\d+(?:[dhms]\d+)*[dhms]?$`)
if !durRe.MatchString(durStr) {
    return fmt.Errorf("duration %q may only contain digits and units d/h/m/s", durStr)
}
d, err := core.ParseDurationString(durStr)

Type guard

func hasOnlyKnownUnits(s string) bool {
    for _, c := range s {
        if (c < '0' || c > '9') && !strings.ContainsRune("dhms", c) {
            return false
        }
    }
    return len(s) > 0
}

Try / catch

d, err := core.ParseDurationString(input)
if err != nil {
    if strings.Contains(err.Error(), "unknown time duration type") {
        log.Printf("unsupported unit in %q; only d, h, m, s allowed", input)
        return
    }
    return err
}

Prevention

When it happens

Trigger: Including unsupported unit letters or stray symbols in the duration string, e.g. '5w', '2h30min', '1d 5h' (the space triggers it), '3x'.

Common situations: Using Go-style units like 'ms', 'us', 'ns' or 'w' for weeks, pasting durations with spaces, writing 'min' instead of 'm'.

Understand the failure class

Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.

Related errors


AI-assisted analysis of kgretzky/evilginx2@4c0988a1d9 (2026-09-05). Data as JSON: /api/errors/56046ad1926df89c. Report an issue: GitHub.