{"record":{"id":"4ab0164ce4b06add","repo":"twentyhq/twenty","slug":"amount-must-be-defined-and-greater-than-0-for-rela","errorCode":null,"errorMessage":"Amount must be defined and greater than 0 for relative date filters","messagePattern":"Amount must be defined and greater than 0 for relative date filters","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-front/src/modules/views/view-filter-value/utils/stringifyRelativeDateFilter.ts","lineNumber":16,"sourceCode":"import { detectCalendarStartDay } from '@/localization/utils/detection/detectCalendarStartDay';\nimport { isNonEmptyString } from '@sniptt/guards';\nimport { isDefined, type RelativeDateFilter } from 'twenty-shared/utils';\n\nexport const stringifyRelativeDateFilter = (\n  relativeDateFilter: RelativeDateFilter,\n) => {\n  let relativeDateFilterStringified = `${relativeDateFilter.direction}_${relativeDateFilter.amount?.toString() ?? '1'}_${relativeDateFilter.unit}`;\n\n  if (relativeDateFilter.direction === 'THIS') {\n    relativeDateFilterStringified = `THIS_1_${relativeDateFilter.unit}`;\n  } else if (\n    !isDefined(relativeDateFilter.amount) ||\n    relativeDateFilter.amount <= 0\n  ) {\n    throw new Error(\n      'Amount must be defined and greater than 0 for relative date filters',\n    );\n  }\n\n  if (isNonEmptyString(relativeDateFilter.timezone)) {\n    relativeDateFilterStringified = `${relativeDateFilterStringified};;${relativeDateFilter.timezone};;`;\n\n    const firstDayOfTheWeek =\n      relativeDateFilter.firstDayOfTheWeek ?? detectCalendarStartDay();\n\n    if (isNonEmptyString(firstDayOfTheWeek)) {\n      relativeDateFilterStringified = `${relativeDateFilterStringified}${firstDayOfTheWeek};;`;\n    }\n  }\n\n  return relativeDateFilterStringified;\n};\n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-front/src/modules/views/view-filter-value/utils/stringifyRelativeDateFilter.ts#L1-L34","documentation":"stringifyRelativeDateFilter throws when the RelativeDateFilter direction is anything other than 'THIS' (i.e., PAST or FUTURE) and the amount is undefined or <= 0. 'THIS' defaults to 1, but relative offset directions require an explicit positive amount.","triggerScenarios":"Constructing a RelativeDateFilter with direction 'PAST'/'FUTURE' but amount omitted, set to 0, or negative. Programmatic default that leaves amount undefined.","commonSituations":"UI initializes a new relative date filter with amount 0. Migration/import producing filters with null amount. Test fixtures that omit the amount field.","solutions":["Ensure amount is a positive integer (>=1) whenever direction is PAST or FUTURE.","Default amount to 1 at the call site when creating a non-THIS relative filter.","Add a UI guard disabling save when amount is empty or <= 0."],"exampleFix":"// before: { direction: 'PAST', amount: 0, unit: 'DAY' }\n// after:  { direction: 'PAST', amount: 1, unit: 'DAY' }","handlingStrategy":"validation","validationCode":"const assertRelativeDateFilter = (f: RelativeDateFilter) => {\n  if (f.direction !== 'THIS' && (!isDefined(f.amount) || f.amount <= 0)) {\n    throw new Error('Amount must be defined and greater than 0 for relative date filters');\n  }\n};","typeGuard":"const isUsableRelativeDateFilter = (f: RelativeDateFilter): boolean =>\n  f.direction === 'THIS' || (isDefined(f.amount) && f.amount > 0);","tryCatchPattern":null,"preventionTips":["Default amount to 1 when creating PAST/FUTURE filters in the UI.","Disable the save button when amount is empty or <= 0 for non-THIS directions.","Sanitize imported/migrated filters to coerce null amount to 1."],"tags":["views","filters","date","validation"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}