Skip to main content

isDateDrivenQuery()

function isDateDrivenQuery(query: string, options?: IsDateDrivenQueryOptions): boolean;

Returns whether a filter query leads with dates rather than with priority.

Todoist gives every filter one of two default hierarchies, and a query that mentions dates gets the date-first one. Pass the answer to sortTasks as its defaultOrder:

sortTasks(tasks, {
sortedBy: savedOptions?.sortedBy,
sortOrder: savedOptions?.sortOrder,
defaultOrder: isDateDrivenQuery(query, { lang }) ? 'DATE_FIRST' : 'PRIORITY_FIRST',
})

The query is read in lang, the account language getUser returns, the way the API reads it. English keywords parse under every language, so lang only matters for a query written in the account's own: sin fecha is a keyword under es and an unreadable phrase under en.

Commas divide a filter into subqueries and Todoist draws each one as its own list, with its own hierarchy. Classify them one at a time for exact results; a whole query answers true only when every subquery is date-driven.

Two kinds of unreadable query part company here. One that breaks the grammar, such as (today, returns false. One that only breaks the vocabulary, such as sin fecha under en, returns true, because a word this package doesn't recognize is treated as a bare date. Pass the account's own lang and the question doesn't arise; get it wrong and a keyword can read as a date.

The function performs no I/O.

Parameters

ParameterType
querystring
optionsIsDateDrivenQueryOptions

Returns

boolean

See

sortTasks