pinpoint-apm/pinpoint · error · Error

Unknown time unit

Error message

Unknown time unit

What it means

Thrown by convertTimeStringToTime when the input string does not end with one of the supported unit suffixes m/h/d after a numeric value. The regex ^(\d+)([mhd])$ fails to capture a unit (e.g. input like '30s', '1w', or a malformed string), leaving unit undefined so the switch falls through to the default branch.

Source

Thrown at web-frontend/src/main/v3/packages/ui/src/utils/date.ts:129

  return `${format(date, firstFormat)}\n${format(date, secondFormat)}`;
};

export const convertTimeStringToTime = (timeString: string) => {
  const timePattern = /^(\d+)([mhd])$/;
  const match = timeString.match(timePattern);
  const value = Number(match?.[1]);
  const unit = match?.[2];

  switch (unit) {
    case 'm':
      return value * 60 * 1000;
    case 'h':
      return value * 60 * 60 * 1000;
    case 'd':
      return value * 24 * 60 * 60 * 1000;
    default:
      throw new Error('Unknown time unit');
  }
};

/**
 * Format a Date as ISO 8601 Basic UTC string: yyyyMMddTHHmmssZ
 * e.g. 20260413T053000Z
 */
export const toBasicISOString = (date: Date): string => {
  const pad = (n: number) => String(n).padStart(2, '0');
  return (
    `${date.getUTCFullYear()}${pad(date.getUTCMonth() + 1)}${pad(date.getUTCDate())}` +
    `T${pad(date.getUTCHours())}${pad(date.getUTCMinutes())}${pad(date.getUTCSeconds())}Z`
  );
};

/**
 * Format a Date as ISO 8601 Basic UTC string with milliseconds: yyyyMMddTHHmmss.SSSZ
 * e.g. 20260413T053000.999Z

View on GitHub (pinned to 744c3d3075)

Solutions

  1. Use only s/m/h/d suffixes in the time string
  2. Convert unsupported units manually, e.g. '2w' -> '14d'
  3. Extend the switch with the needed unit case
  4. Validate/parse the duration string with a regex before calling

Example fix

// before
convertTimeStringToTime('10min');
// after
convertTimeStringToTime('10m'); // or: /^\d+[smhd]$/.test(str) check before calling
Defensive patterns

Strategy: validation

Validate before calling

const m = /^([0-9]+)([smhd])$/.exec(timeString.trim());
if (!m) throw new RangeError(`time string must match <number><s|m|h|d>, got '${timeString}'`);

Try / catch

try { ms = convertTimeStringToTime(str); } catch (e) { if (e.message === 'Unknown time unit') { log.warn(`bad duration ${str}, using default`); ms = defaultMs; } else throw e; }

Prevention

When it happens

Trigger: Passing a time string whose suffix is not one of 's','m','h','d', e.g. convertTimeStringToTime('30w') or '45', or a string where the unit extraction yields an unexpected character.

Common situations: Config values written as '10min' or '2hr', week/month units not covered by the parser, trailing whitespace or typo in a properties file, copied durations from another system using a richer unit set.

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 pinpoint-apm/pinpoint@744c3d3075 (2026-09-07). Data as JSON: /api/errors/546872cae35ac124. Report an issue: GitHub.