Skip to content

Commit

Permalink
Fix past n filters (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
whscullin authored Nov 11, 2024
1 parent 15e553b commit c4ed8ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/query-composer/src/core/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export function timeFilterToString(field: string, filter: TimeFilter): string {
const quotedField = maybeQuoteIdentifier(field);
switch (filter.type) {
case 'is_in_the_past':
return `${quotedField}: now - ${filter.amount} ${filter.unit} for ${filter.amount} ${filter.unit}`;
return `${quotedField} ? now - ${filter.amount} ${filter.unit} for ${filter.amount} ${filter.unit}`;
case 'is_last':
return `${quotedField}.${filter.period} = now.${filter.period} - 1 ${filter.period}`;
case 'is_this':
Expand Down Expand Up @@ -260,7 +260,7 @@ export function timeFilterToString(field: string, filter: TimeFilter): string {
return `${quotedField} != null`;
case 'custom':
default:
return `${quotedField}: ${filter.partial}`;
return `${quotedField} ? ${filter.partial}`;
}
}

Expand Down Expand Up @@ -551,7 +551,7 @@ const NUM_GTE_FILTER = new RegExp(`^(${FIELD})\\s*>=\\s*(${NUMBER})$`);

const TIME_UNIT = `(?:year|quarter|month|week|day|hour|minute|second)`;
const TIME_PAST_FILTER = new RegExp(
`^(${FIELD})\\s*:\\s*now\\s*-\\s*(${NUMBER})\\s*(${TIME_UNIT})s?\\s*for\\s*\\s*(${NUMBER})\\s*(${TIME_UNIT})s?$`
`^(${FIELD})\\s*\\?\\s*now\\s*-\\s*(${NUMBER})\\s*(${TIME_UNIT})s?\\s*for\\s*\\s*(${NUMBER})\\s*(${TIME_UNIT})s?$`
);
const TIME_LAST_FILTER = new RegExp(
`^(${FIELD})\\.(${TIME_UNIT})\\s*=\\s*now\\.(${TIME_UNIT})\\s*-\\s*1\\s*(${TIME_UNIT})$`
Expand Down
2 changes: 1 addition & 1 deletion packages/query-composer/tests/core/filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const TIME_FILTER_TO_STRING: [TimeFilter, string][] = [
],
[
{type: 'is_in_the_past', amount: 1, unit: 'days'},
'a: now - 1 days for 1 days',
'a ? now - 1 days for 1 days',
],
[{type: 'is_last', period: 'day'}, 'a.day = now.day - 1 day'],
[{type: 'is_null'}, 'a = null'],
Expand Down

0 comments on commit c4ed8ab

Please sign in to comment.