{"record":{"id":"546872cae35ac124","repo":"pinpoint-apm/pinpoint","slug":"unknown-time-unit","errorCode":null,"errorMessage":"Unknown time unit","messagePattern":"Unknown time unit","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web-frontend/src/main/v3/packages/ui/src/utils/date.ts","lineNumber":129,"sourceCode":"\n  return `${format(date, firstFormat)}\\n${format(date, secondFormat)}`;\n};\n\nexport const convertTimeStringToTime = (timeString: string) => {\n  const timePattern = /^(\\d+)([mhd])$/;\n  const match = timeString.match(timePattern);\n  const value = Number(match?.[1]);\n  const unit = match?.[2];\n\n  switch (unit) {\n    case 'm':\n      return value * 60 * 1000;\n    case 'h':\n      return value * 60 * 60 * 1000;\n    case 'd':\n      return value * 24 * 60 * 60 * 1000;\n    default:\n      throw new Error('Unknown time unit');\n  }\n};\n\n/**\n * Format a Date as ISO 8601 Basic UTC string: yyyyMMddTHHmmssZ\n * e.g. 20260413T053000Z\n */\nexport const toBasicISOString = (date: Date): string => {\n  const pad = (n: number) => String(n).padStart(2, '0');\n  return (\n    `${date.getUTCFullYear()}${pad(date.getUTCMonth() + 1)}${pad(date.getUTCDate())}` +\n    `T${pad(date.getUTCHours())}${pad(date.getUTCMinutes())}${pad(date.getUTCSeconds())}Z`\n  );\n};\n\n/**\n * Format a Date as ISO 8601 Basic UTC string with milliseconds: yyyyMMddTHHmmss.SSSZ\n * e.g. 20260413T053000.999Z","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/web-frontend/src/main/v3/packages/ui/src/utils/date.ts#L111-L147","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use only s/m/h/d suffixes in the time string","Convert unsupported units manually, e.g. '2w' -> '14d'","Extend the switch with the needed unit case","Validate/parse the duration string with a regex before calling"],"exampleFix":"// before\nconvertTimeStringToTime('10min');\n// after\nconvertTimeStringToTime('10m'); // or: /^\\d+[smhd]$/.test(str) check before calling","handlingStrategy":"validation","validationCode":"const m = /^([0-9]+)([smhd])$/.exec(timeString.trim());\nif (!m) throw new RangeError(`time string must match <number><s|m|h|d>, got '${timeString}'`);","typeGuard":null,"tryCatchPattern":"try { ms = convertTimeStringToTime(str); } catch (e) { if (e.message === 'Unknown time unit') { log.warn(`bad duration ${str}, using default`); ms = defaultMs; } else throw e; }","preventionTips":["Validate duration strings with a regex at config load time","Convert richer units (w, mo) to d/s before passing in","Keep a canonical duration format documented for config files","Trim whitespace from config values"],"tags":["datetime","duration","parsing"],"backgroundTag":"invalid-duration-format","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}