Confused: Compound conditions in a filter

I am not sure if I have “coders block” but I thought I knew how to do this, so I am asking for some assistance please;

<$list filter="[has[outstanding-date]!has[done-date]]" counter=item>
   <$list filter="[<item>match[1]]"><h4>''Outstanding''</h4></$list>
   <$link/><br>
</$list>
  • The above lists all items with an outstanding-date and no done-date.
  • Only if more than one is available will the heading display

However I want this list only to list the titles where the outstanding-date is less than or equal to today. I need to use a filter something like this get[outstanding-date]compare:date:lteq<now YYYY0MM0DD>. In a separate list I will list greater than today.

  • However I am having trouble combining it with the existing filter without loosing the title.

Any help appreciated.

1 Like

I haven’t tested, but I’d try something like

[has[outstanding-date]!has[done-date]] :filter[get[outstanding-date]compare:date:lteq<now YYYY0MM0DD>]
2 Likes

Thanks @etardiff the filter you have when you need a filter. Perhaps It is better memorised as the “each title” or even “test each title” filter run.

1 Like

You can give this a try

<$let
   FindOutstanding="[has[outstanding-date]!has[done-date]] :filter[get[outstanding-date]format:date[YYYY0MM0DD]compare:date:lteq<now YYYY0MM0DD>]"
   GetCount={{{ [subfilter<FindOutstanding>count[]] }}} 
>

<$list filter="[<GetCount>compare:integer:gt[1]]"><h4>''Outstanding''</h4></$list>

<$list filter="[subfilter<FindOutstanding>]">
   <$link  /><br>
</$list>

</$let>

@Brian_Radspinner that is an interesting alternative approach that may be more valuable in other circumstances.

Both @etardiff and your solution introduce different patterns, but the answer for both is using the filter run. Which I may add it may be more useable, perhaps, than the map filter run in many common cases.

It takes time to learn every approach, or feature, now I can conceptualise it as “test each title” it has taken since Release 5.1.23 Released 25th December 2020 at 00:29

Now I need to revisit the Filter Operator and understand how it differs from the subfilter operator. Basically it appears the current tiddler is the title inside the filter operator where it is not in the subfilter.

Now we also need to review it in relation to TW 5.3.0’s function and function operator.

I like to think of filter and :filter as strainers: they permit input titles that “fit” (that is, titles that would yield a result when passed through the filter) to pass through, but don’t alter them in any other way.

subfilter is more akin to :map, and conceptually a bit closer to the usual function of filters in TW. Both output a list of titles that have been appropriately modified by the filter operations they enclose, and may or may not resemble their input in any way.


Tangentially: I like the way you handled the conditional display of the header, by the way—very neat. I’m always forgetting about list counters.

2 Likes

As usual I don’t stop with the answer, I go on to try and design for easy reuse and now I am getting the same result for both of the following lists.

\define outstanding() [has[outstanding-date]!has[done-date]]
\define now-outstanding() [get[outstanding-date]compare:date:lteq<now "[UTC]YYYY0MM0DD0hh0mm0ss0XXX">]
\define not-outstanding() [get[outstanding-date]compare:date:gt<now "[UTC]YYYY0MM0DD0hh0mm0ss0XXX">]
<div>

{{{ [<now "[UTC]YYYY0MM0DD">] }}}
<$list filter="[subfilter<outstanding>] :filter[<now-outstanding>]" counter=item>
   <$list filter="[<item>match[1]]"><h4>''Outstanding now''</h4></$list>
   <$link/> <$view field=outstanding-date format="relativedate"/><br>
</$list>

<$list filter="[subfilter<outstanding>]  :filter[<not-outstanding>]" counter=item>
   <$list filter="[<item>match[1]]"><h4>''Not yet Outstanding''</h4></$list>
   <$link/> <$view field=outstanding-date format="relativedate"/><br>
</$list>
  • This just should not happen given the compare are lteq vs gt
  • It happens if I use either
    • <now "[UTC]YYYY0MM0DD0hh0mm0ss0XXX">
    • or <now "[UTC]YYYY0MM0DD">

Snag_13a22f2

Arghhh!

In order to apply a filter that is stored in a variable, you need to use the subfilter<varname> syntax.

Try this:

<$list filter="[subfilter<outstanding>] :filter[subfilter<now-outstanding>]" counter=item>

and

<$list filter="[subfilter<outstanding>]  :filter[subfilter<not-outstanding>]" counter=item>
3 Likes

Perfect @EricShulman now working.

There will be a nicer approach in TW 5.3.0 with functions, although I am a little uncertain about the recent inclusion of “.” names.