{"record":{"id":"474581ea44f81af8","repo":"n8n-io/n8n","slug":"unsupported-unit-string-errorunit-supported","errorCode":null,"errorMessage":"Unsupported unit '${String(errorUnit)}'. Supported: ${durationUnits.map((u) => `'${u}'`).join(', ')}.","messagePattern":"Unsupported unit '(.+?)'\\. Supported: (.+?)'`\\)\\.join\\(', '\\)\\}\\.","errorType":"exception","errorClass":"ExpressionExtensionError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/expression-runtime/src/extensions/date-extensions.ts","lineNumber":247,"sourceCode":"\n\tif (isDateTime(date)) return date.plus(duration);\n\n\treturn DateTime.fromJSDate(date).plus(duration).toJSDate();\n}\n\nfunction diffTo(date: DateTime, args: [string | Date | DateTime, DurationUnit | DurationUnit[]]) {\n\tconst [otherDate, unit = 'days'] = args;\n\tlet units = Array.isArray(unit) ? unit : [unit];\n\n\tif (units.length === 0) {\n\t\tunits = ['days'];\n\t}\n\n\tconst allowedUnitSet = new Set([...dateParts, ...durationUnits]);\n\tconst errorUnit = units.find((u) => !allowedUnitSet.has(u));\n\n\tif (errorUnit) {\n\t\tthrow new ExpressionExtensionError(\n\t\t\t`Unsupported unit '${String(errorUnit)}'. Supported: ${durationUnits\n\t\t\t\t.map((u) => `'${u}'`)\n\t\t\t\t.join(', ')}.`,\n\t\t);\n\t}\n\n\tconst diffResult = date.diff(toDateTime(otherDate), units);\n\n\tif (units.length > 1) {\n\t\treturn diffResult.toObject();\n\t}\n\n\treturn diffResult.as(units[0]);\n}\n\nfunction diffToNow(date: DateTime, args: [DurationUnit | DurationUnit[]]) {\n\tconst [unit] = args;\n\treturn diffTo(date, [DateTime.now(), unit]);","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/expression-runtime/src/extensions/date-extensions.ts#L229-L265","documentation":"`.diffTo(other, unit)` accepts a duration unit (or an array of units) drawn from the union of `dateParts` (`day`,`week`,`month`,`year`,`hour`,`minute`,`second`,...) and `durationUnits` (`milliseconds`,`seconds`,`minutes`,`hours`,`days`,`weeks`,`months`,`quarters`,`years`). The first element outside that set triggers the throw and the message echoes the supported list. Note the message lists only `durationUnits`, but singular `dateParts` are also accepted.","triggerScenarios":"Using singular-but-unsupported or misspelled units: `.diffTo(other, 'fortnight')`, `.diffTo(other, 'dayss')`, or `.diffTo(other, ['days', 'centuries'])`.","commonSituations":"Assuming Luxon's full unit catalogue is accepted; using the wrong singular/plural form (e.g. `'day'` works via dateParts but `'days'` is the duration form); typos.","solutions":["Use one of the supported units shown in the error message (e.g. `days`, `hours`, `minutes`, `seconds`, `months`, `years`).","When passing an array, ensure every element is in the allowed set.","If you need a unit n8n does not expose, compute the diff in a Code node using Luxon directly."],"exampleFix":"// before\n{{ $json.start.diffTo($json.end, 'fortnights') }}\n// after\n{{ $json.start.diffTo($json.end, 'days') }}","handlingStrategy":"validation","validationCode":"const ALLOWED = new Set([\n  'milliseconds','seconds','minutes','hours','days','weeks','months','quarters','years',\n  'day','week','month','year','hour','minute','second'\n]);\nconst unit = $json.unit;\nconst units = Array.isArray(unit) ? unit : [unit];\nconst bad = units.find((u) => !ALLOWED.has(u));\nif (bad) throw new Error(`Unsupported diffTo unit: ${bad}`);\nreturn $json;","typeGuard":"const isSupportedUnit = (u: string): boolean =>\n  ['milliseconds','seconds','minutes','hours','days','weeks','months','quarters','years','day','week','month','year','hour','minute','second'].includes(u);","tryCatchPattern":null,"preventionTips":["Prefer plural duration forms (`days`, `hours`) for diffs.","When passing a unit array, validate every element against the allowed set.","Compute exotic units in a Code node with Luxon directly."],"tags":["expression","date","units","validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}