1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Adding support for 0 day ago number in date pattern search

This commit is contained in:
Patrik J. Braun 2023-09-08 23:14:52 +02:00
parent b383b7f585
commit 5368b4ed4e
3 changed files with 8 additions and 3 deletions

View File

@ -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);

View File

@ -394,7 +394,7 @@ export class SearchQueryParser {
str.startsWith(this.keywords.sameDay + '!:')) && {
negate: true
}),
...(ago && {agoNumber: ago})
...(!isNaN(ago) && {agoNumber: ago})
} as DatePatternSearch;
}
}

View File

@ -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,