From 5368b4ed4e1a61097dbc88aa076aaf9c21524a8d Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Fri, 8 Sep 2023 23:14:52 +0200 Subject: [PATCH] Adding support for 0 day ago number in date pattern search --- src/backend/model/database/SearchManager.ts | 4 ++-- src/common/SearchQueryParser.ts | 2 +- test/common/unit/SearchQueryParser.ts | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/model/database/SearchManager.ts b/src/backend/model/database/SearchManager.ts index 7396f68a..00bd35ed 100644 --- a/src/backend/model/database/SearchManager.ts +++ b/src/backend/model/database/SearchManager.ts @@ -758,8 +758,8 @@ export class SearchManager { tq.frequency === DatePatternFrequency.weeks_ago || tq.frequency === DatePatternFrequency.days_ago)) { - if (!tq.agoNumber) { - throw new Error('ago number is missing on date patter search query with frequency: ' + DatePatternFrequency[tq.frequency]); + if (isNaN(tq.agoNumber)) { + throw new Error('ago number is missing on date patter search query with frequency: ' + DatePatternFrequency[tq.frequency] + ', ago number: ' + tq.agoNumber); } const to = new Date(); to.setHours(0, 0, 0, 0); diff --git a/src/common/SearchQueryParser.ts b/src/common/SearchQueryParser.ts index 1bb22edf..e6aaed02 100644 --- a/src/common/SearchQueryParser.ts +++ b/src/common/SearchQueryParser.ts @@ -394,7 +394,7 @@ export class SearchQueryParser { str.startsWith(this.keywords.sameDay + '!:')) && { negate: true }), - ...(ago && {agoNumber: ago}) + ...(!isNaN(ago) && {agoNumber: ago}) } as DatePatternSearch; } } diff --git a/test/common/unit/SearchQueryParser.ts b/test/common/unit/SearchQueryParser.ts index 279a914f..02f551b2 100644 --- a/test/common/unit/SearchQueryParser.ts +++ b/test/common/unit/SearchQueryParser.ts @@ -133,6 +133,11 @@ describe('SearchQueryParser', () => { type: SearchQueryTypes.date_pattern, daysLength: i, frequency: DatePatternFrequency.every_year } as DatePatternSearch); + check({ + type: SearchQueryTypes.date_pattern, daysLength: i, + frequency: DatePatternFrequency.days_ago, + agoNumber: 0 + } as DatePatternSearch); check({ type: SearchQueryTypes.date_pattern, daysLength: i, frequency: DatePatternFrequency.days_ago,