{"record":{"id":"b991c6fe3b87d266","repo":"pinpoint-apm/pinpoint","slug":"invalid-time-unit-provided","errorCode":null,"errorMessage":"Invalid time unit provided.","messagePattern":"Invalid time unit provided\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web-frontend/src/main/v3/packages/datetime-picker/src/utils/date.ts","lineNumber":66,"sourceCode":"        case 's':\n          return timeNumber * 1000;\n        case 'm':\n          return timeNumber * 60 * 1000;\n        case 'h':\n          return timeNumber * 60 * 60 * 1000;\n        case 'd':\n          return timeNumber * 24 * 60 * 60 * 1000;\n        case 'w':\n          return timeNumber * 7 * 24 * 60 * 60 * 1000;\n        case 'mo':\n          return timeNumber * 30 * 24 * 60 * 60 * 1000;\n        case 'y':\n          return timeNumber * 365 * 24 * 60 * 60 * 1000;\n        default:\n          break;\n      }\n    }\n    throw new Error('Invalid time unit provided.');\n  }\n};\n\nexport const convertToTimeUnit = (milliseconds = 0): TimeUnitFormat => {\n  const seconds = Math.ceil(milliseconds / 1000);\n  const minutes = Math.floor(seconds / 60);\n  const hours = Math.floor(minutes / 60);\n  const days = Math.floor(hours / 24);\n  const weeks = Math.floor(days / 7);\n  const months = Math.floor(days / 30);\n  const years = Math.floor(months / 12);\n\n  if (years >= 1) {\n    return `${years}y`;\n  } else if (months >= 1) {\n    return `${months}mo`;\n  } else if (weeks >= 1) {\n    return `${weeks}w`;","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/web-frontend/src/main/v3/packages/datetime-picker/src/utils/date.ts#L48-L84","documentation":"convertToMilliseconds converts a time value with a unit ('s','m','h','d','w','y') into milliseconds. When the unit string does not match any known case, the switch falls through to default and the function throws 'Invalid time unit provided.' to signal an unrecognized TimeUnitFormat.","triggerScenarios":"Calling convertToMilliseconds with a unit string outside the supported set, e.g. convertToMilliseconds(5, 'M') or 'sec', or with an empty/undefined unit that fails the inner lookup, hitting the default branch.","commonSituations":"Passing a capitalized unit like 'Y' or 'H', using 'mo' for months (not supported), units arriving from user input or config files without normalization, or refactoring a legacy time-unit constant that used full words.","solutions":["Check the unit value against the supported set ('s','m','h','d','w','y') before calling","Normalize/trim/lowercase the input unit string","Add the missing unit case to the switch if the new unit is legitimately needed","Add a validation warning in dev so unknown units are caught early"],"exampleFix":"// before\nconvertToMilliseconds(10, 'M');\n// after\nconvertToMilliseconds(10, 'm'); // or validate first:\nconst units = ['s','m','h','d','w','y'];\nif (!units.includes(unit)) throw new Error(`Unit must be one of ${units.join(',')}`);","handlingStrategy":"validation","validationCode":"const SUPPORTED = ['s','m','h','d','w','y'];\nif (!SUPPORTED.includes(unit)) throw new RangeError(`unit must be one of ${SUPPORTED.join(',')}, got ${unit}`);","typeGuard":"const isTimeUnit = (u: unknown): u is 's'|'m'|'h'|'d'|'w'|'y' =>\n  typeof u === 'string' && ['s','m','h','d','w','y'].includes(u);","tryCatchPattern":"try { ms = convertToMilliseconds(value, unit); } catch (e) { if (e.message === 'Invalid time unit provided.') { ms = fallbackMs; } else throw e; }","preventionTips":["Normalize unit casing/trimming before calling","Keep unit values as a typed union, not raw strings","Write a table test covering every unit you allow in config"],"tags":["datetime","invalid-argument","validation"],"backgroundTag":"invalid-enum-value","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"}