{"record":{"id":"cb62366f5aad322a","repo":"gchq/CyberChef","slug":"unrecognised-unit-cb6236","errorCode":null,"errorMessage":"Unrecognised unit","messagePattern":"Unrecognised unit","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ToUNIXTimestamp.mjs","lineNumber":70,"sourceCode":"     *\n     * @throws {OperationError} if unit unrecognised\n     */\n    run(input, args) {\n        const [units, treatAsUTC, showDateTime] = args,\n            d = treatAsUTC ? moment.utc(input) : moment(input);\n\n        let result = \"\";\n\n        if (units === \"Seconds (s)\") {\n            result = d.unix();\n        } else if (units === \"Milliseconds (ms)\") {\n            result = d.valueOf();\n        } else if (units === \"Microseconds (μs)\") {\n            result = d.valueOf() * 1000;\n        } else if (units === \"Nanoseconds (ns)\") {\n            result = d.valueOf() * 1000000;\n        } else {\n            throw new OperationError(\"Unrecognised unit\");\n        }\n\n        return showDateTime ? `${result} (${d.tz(\"UTC\").format(\"ddd D MMMM YYYY HH:mm:ss\")} UTC)` : result.toString();\n    }\n\n}\n\nexport default ToUNIXTimestamp;\n","sourceCodeStart":52,"sourceCodeEnd":79,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ToUNIXTimestamp.mjs#L52-L79","documentation":"To UNIX Timestamp maps the selected Units argument to a multiplication of the moment value. If Units is none of the supported strings ('Seconds (s)', 'Milliseconds (ms)', 'Microseconds (μs)', 'Nanoseconds (ns)'), the final else branch throws 'Unrecognised unit'. This typically indicates the option list was changed or the argument was supplied programmatically with an invalid value.","triggerScenarios":"Passing a Units argument whose value is not one of the four supported option strings — e.g. via a programmatic recipe that sets an arbitrary string, or after editing the option list.","commonSituations":"Custom/programmatic recipe building that injects an invalid unit string; a locale-edited option label; a stale recipe referencing a renamed unit.","solutions":["Set Units to one of the four supported values: Seconds (s), Milliseconds (ms), Microseconds (μs), or Nanoseconds (ns).","If building the recipe programmatically, copy the exact option string including the unit abbreviation in parentheses.","Regenerate the recipe through the UI to reset the option."],"exampleFix":"// before: args[0] (Units) = \"Seconds\"      -> not matched -> throws\n// after:  args[0] (Units) = \"Seconds (s)\"    -> matched, returns unix seconds","handlingStrategy":"validation","validationCode":"const ALLOWED = [\"Seconds (s)\", \"Milliseconds (ms)\", \"Microseconds (μs)\", \"Nanoseconds (ns)\"];\nif (!ALLOWED.includes(units)) throw new Error(`Unsupported unit: ${units}`);","typeGuard":"const isSupportedUnit = u => [\"Seconds (s)\", \"Milliseconds (ms)\", \"Microseconds (μs)\", \"Nanoseconds (ns)\"].includes(u);","tryCatchPattern":"try { toUnixTimestamp(input, [units, treatAsUTC, showDateTime]); }\ncatch (e) { if (/Unrecognised unit/.test(e.message)) { units = \"Seconds (s)\"; } else throw e; }","preventionTips":["Always select the unit from the option list rather than typing it.","When building recipes in code, copy the exact option string.","Re-add the operation via the UI to reset the argument."],"tags":["datetime","unix-timestamp","validation","argument"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}