Thanks. But I’m lost I do not know how to do that…
Something like this:
#+BEGIN_QUERY
{
:inputs [:today :+7d :+13d]
:query [:find (pull ?b [*])
:in $ ?today ?next7 ?next13 %
:where
(or
(and [(+ ?today 1) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(+ ?today 2) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(+ ?today 3) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(+ ?today 4) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(+ ?today 5) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(+ ?today 6) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(+ ?today 7) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(- ?next7 6) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(- ?next7 5) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(- ?next7 4) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(- ?next7 3) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(- ?next7 2) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(- ?next7 1) ?weekBegin] (isWeekDay ?weekBegin 1))
(and [(- ?next7 0) ?weekBegin] (isWeekDay ?weekBegin 1))
)
(or
(and [(+ ?next7 0) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(+ ?next7 1) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(+ ?next7 2) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(+ ?next7 3) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(+ ?next7 4) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(+ ?next7 5) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(+ ?next7 6) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(- ?next13 6) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(- ?next13 5) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(- ?next13 4) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(- ?next13 3) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(- ?next13 2) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(- ?next13 1) ?weekEnd] (isWeekDay ?weekEnd 0))
(and [(- ?next13 0) ?weekEnd] (isWeekDay ?weekEnd 0))
)
(task ?b #{"TODO"})
(or
[?b :block/scheduled ?date]
[?b :block/deadline ?date]
)
[(>= ?date ?weekBegin)]
[(<= ?date ?weekEnd)]
]
:rules [
[(isWeekDay ?date ?num)
[(mod ?date 100) ?monthday]
[(mod ?date 10000) ?mod]
[(quot ?mod 100) ?month]
[(- ?month 8) ?month8]
[(quot ?month8 6) ?month6]
[(* ?month6 12) ?month12]
[(- ?month ?month12) ?monthnum]
[(inc ?monthnum) ?monthinc]
[(* 13 ?monthinc) ?month13]
[(quot ?month13 5) ?month5]
[(quot ?date 10000) ?year]
[(+ ?year ?month6) ?year6]
[(mod ?year6 100) ?yearnum]
[(quot ?yearnum 4) ?year4]
[(quot ?year6 100) ?century]
[(quot ?century 4) ?century4]
[(* 5 ?century) ?century5]
[(+ ?monthday ?month5 ?yearnum ?year4 ?century4 ?century5) ?sum]
[(mod ?sum 7) ?d]
[(= ?d ?num)]
]
]
}
#+END_QUERY
The above code:
- turned out double than it should, in the effort to cover the cases when the month (or even the year) changes during the week
- is relatively slow
- assumes that a week:
- begins on Sunday (all the
(isWeekDay ?weekBegin 1)
) - ends on Saturday (all the
(isWeekDay ?weekEnd 0)
)
- begins on Sunday (all the
2 Likes
Thanks.
I tried and it works perfectly. The down side, as you said, it is very slow.
Do you know if the Lgoseq team is thinking on introducing a better calendar structure with Year month days and also weeks? this would make this kind of query much easier.
I edited the query to move some lines around. Now it should be faster.
I don’t have any internal team knowledge.
1 Like
It is working perfectly thanks!!!