mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add date variables to date search
This commit is contained in:
parent
2c9ec454f5
commit
98faefa644
1 changed files with 40 additions and 11 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
|
import { DateTime } from 'luxon'
|
||||||
import {
|
import {
|
||||||
ISearchParserDictionary,
|
ISearchParserDictionary,
|
||||||
parse,
|
parse,
|
||||||
|
|
@ -244,21 +245,49 @@ const parseDateFilter = (
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (field.toLowerCase()) {
|
||||||
|
case 'published':
|
||||||
|
field = 'published_at'
|
||||||
|
break
|
||||||
|
case 'saved':
|
||||||
|
field = 'saved_at'
|
||||||
|
break
|
||||||
|
case 'updated':
|
||||||
|
field = 'updated_at'
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for special date filters
|
||||||
|
switch (str.toLowerCase()) {
|
||||||
|
case 'today':
|
||||||
|
return {
|
||||||
|
field,
|
||||||
|
startDate: DateTime.local().startOf('day').toJSDate(),
|
||||||
|
}
|
||||||
|
case 'yesterday': {
|
||||||
|
const yesterday = DateTime.local().minus({ days: 1 })
|
||||||
|
return {
|
||||||
|
field,
|
||||||
|
startDate: yesterday.startOf('day').toJSDate(),
|
||||||
|
endDate: yesterday.endOf('day').toJSDate(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'this week':
|
||||||
|
return {
|
||||||
|
field,
|
||||||
|
startDate: DateTime.local().startOf('week').toJSDate(),
|
||||||
|
}
|
||||||
|
case 'this month':
|
||||||
|
return {
|
||||||
|
field,
|
||||||
|
startDate: DateTime.local().startOf('month').toJSDate(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for date ranges
|
||||||
const [start, end] = str.split('..')
|
const [start, end] = str.split('..')
|
||||||
const startDate = start && start !== '*' ? new Date(start) : undefined
|
const startDate = start && start !== '*' ? new Date(start) : undefined
|
||||||
const endDate = end && end !== '*' ? new Date(end) : undefined
|
const endDate = end && end !== '*' ? new Date(end) : undefined
|
||||||
|
|
||||||
switch (field.toUpperCase()) {
|
|
||||||
case 'PUBLISHED':
|
|
||||||
field = 'published_at'
|
|
||||||
break
|
|
||||||
case 'SAVED':
|
|
||||||
field = 'saved_at'
|
|
||||||
break
|
|
||||||
case 'UPDATED':
|
|
||||||
field = 'updated_at'
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
field,
|
field,
|
||||||
startDate,
|
startDate,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue