Tasks plugin - filter "due within N days"?

What I’m trying to do

Using the Tasks plugin, create a filter which shows all unfinished tasks due in the “next N days”, where N is currently 90, but I will need over values of N for other filters.

Things I have tried

None of the built-in filters offer a way to express “now plus N days”, so I’m trying to write a custom function.

description regex matches /#todo(?!\S)/
not done

# 86400 seconds == 24 hours
# echo "$( date +%s ) + 86400 * 90" | bc  => 1781626874
filter by function \
    const limit = 1781626874 ; \
    return ( task.due.format('X') <= limit ) ;

This seems to work, in that it shows all tasks whose due date is before that specific timestamp, however I have to manually update the limit value every day.

:red_question_mark: Is there a way to calculate “now plus N days”, at the time the query is executed?

As a side note … I am a programmer by trade, but I’m not a javascript programmer.

And OF COURSE, as soon as I submitted the question it occurred to me that maybe the javascript language has a way to do this. (Story of my life.)

This is working:

description regex matches /#todo(?!\S)/
not done

# 86400 seconds == 24 hours
filter by function \
    const limit = Date.now() / 1000 + 86400 * 90 ; \
    return ( task.due.format('X') <= limit ) ;

Note that 86400 * 90 might not be exactly 90 days if there are leap years or leap seconds involved, but it’s close enough for my purposes.

I’ll leave this here as an example for others who may need to do this in the future.

:smiling_face_with_sunglasses:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.