twentyhq/twenty · error · Error
Amount must be defined and greater than 0 for relative date
Error message
Amount must be defined and greater than 0 for relative date filters
What it means
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.
Source
Thrown at packages/twenty-front/src/modules/views/view-filter-value/utils/stringifyRelativeDateFilter.ts:16
import { detectCalendarStartDay } from '@/localization/utils/detection/detectCalendarStartDay';
import { isNonEmptyString } from '@sniptt/guards';
import { isDefined, type RelativeDateFilter } from 'twenty-shared/utils';
export const stringifyRelativeDateFilter = (
relativeDateFilter: RelativeDateFilter,
) => {
let relativeDateFilterStringified = `${relativeDateFilter.direction}_${relativeDateFilter.amount?.toString() ?? '1'}_${relativeDateFilter.unit}`;
if (relativeDateFilter.direction === 'THIS') {
relativeDateFilterStringified = `THIS_1_${relativeDateFilter.unit}`;
} else if (
!isDefined(relativeDateFilter.amount) ||
relativeDateFilter.amount <= 0
) {
throw new Error(
'Amount must be defined and greater than 0 for relative date filters',
);
}
if (isNonEmptyString(relativeDateFilter.timezone)) {
relativeDateFilterStringified = `${relativeDateFilterStringified};;${relativeDateFilter.timezone};;`;
const firstDayOfTheWeek =
relativeDateFilter.firstDayOfTheWeek ?? detectCalendarStartDay();
if (isNonEmptyString(firstDayOfTheWeek)) {
relativeDateFilterStringified = `${relativeDateFilterStringified}${firstDayOfTheWeek};;`;
}
}
return relativeDateFilterStringified;
};
View on GitHub (pinned to 1f5dd2bbd2)
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.
Example fix
// before: { direction: 'PAST', amount: 0, unit: 'DAY' }
// after: { direction: 'PAST', amount: 1, unit: 'DAY' } Defensive patterns
Strategy: validation
Validate before calling
const assertRelativeDateFilter = (f: RelativeDateFilter) => {
if (f.direction !== 'THIS' && (!isDefined(f.amount) || f.amount <= 0)) {
throw new Error('Amount must be defined and greater than 0 for relative date filters');
}
}; Type guard
const isUsableRelativeDateFilter = (f: RelativeDateFilter): boolean => f.direction === 'THIS' || (isDefined(f.amount) && f.amount > 0);
Prevention
- 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.
When it happens
Trigger: Constructing a RelativeDateFilter with direction 'PAST'/'FUTURE' but amount omitted, set to 0, or negative. Programmatic default that leaves amount undefined.
Common situations: UI initializes a new relative date filter with amount 0. Migration/import producing filters with null amount. Test fixtures that omit the amount field.
Related errors
- Failed to create view filter group
- Email and password are required
- No date fields for calendar
- KeyDescriptor element is missing
- KeyInfo element is missing
AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12).
Data as JSON: /api/errors/4ab0164ce4b06add.
Report an issue: GitHub.