Days operator - having problems with supplying parameter from a tiddler field

Hi, can anyone advise on the correct syntax for use with the days operator in a filter?

The tiddlers concerned have a historic date set as a field named ‘last-reviewed3’.

If I write my filter with hard coded numbers…here the example is -800 then it seems to work as expected.

So here is the first part of the filter, and in the following case with a test hard-coded value of -800 it seems to work as expected.

<$list filter=’[all[tiddlers]!is[system]!tag[z hidden]has:field[last-reviewed3]!days:last-reviewed3[-800]

In the above filter, the part…

!days:last-reviewed3[-800]

…allows through only those tiddlers having a ‘last-reviewed3’ date field which is at least 800 days in the past from today and with the hard coded value of -800 this all seems to work as expected.

But actually, instead of the hard coded value of -800 I wish to use a value stored in each tiddler in a field named ‘interval3’ which might be set with the same value of -800 but might equally be -30.

So the filter expression would look something like this…

I have indicated missing syntax which I am struggling to find with as question marks ???

<$list filter=’[all[tiddlers]!is[system]!tag[z hidden]has:field[last-reviewed3]!days:last-reviewed3[???interval3???]

So my question is what syntax do I need to replace the question marks (???) in the above, my attempts so far seem to be failing to get it right. The behaviour observed with my feeble attempts is that the days part of the filter seems to allow everything through when I attempt to use the value in the tiddler field interval3 and in contrast it works with the hard-coded value of -800 etc.

Thanks.

I am storing the historic date in each tiddler in the field named ‘last-reviewed3’ with the tiddlywiki default date format of [UTC]YYYY0MM0DD0hh0mm0ss0XXX

Background: This relates to my first attempts at prototyping a solution to my post

First lets make your example filter complete;

[all[tiddlers]!is[system]!tag[z hidden]has:field[last-reviewed3]!days:last-reviewed3[???interval3???]] was missing closing ]

Now assuming this is otherwise valid you can replace [???interval3???] with {!!fieldname} or <variablename> even {tiddlername} or {tiddlername!!fieldname} notice we are using the single form of the “braces” to delimit the name, where outside filters we need the double braces form {{!!fieldname}} <<varname>>, but since we have the single braces in a filter to delmit the fieldname or variable name, we do not also need the single [ ] around this value.

In other words:

The brackets used to enclose a filter operand indicate how that operand should be interpreted:

  • square brackets – [value] – are used to enclose literal values (i.e., simple text or numbers)
  • curly braces – {reference} – are used to enclose tiddler field references; i.e., {tiddlername!!fieldname}, where the operand value is retrieved from the indicated tiddler field. If the tiddlername portion is omitted – i.e., {!!fieldname} – then the current tiddler is implied. If the !!fieldname portion is omitted – i.e, {tiddlername} – then the !!text field is implied.
  • angle brackets – <varname> – are used to enclose references to variables. Note that macros are also considered to be variables so operands such as <now "YYYY0MM0DD"> can be used here.
3 Likes

ThanksTWTones,

The filter was complete in the code, in an earlier draft I had indicated this but the note got lost in subsequent edits - sorry.

I had tried {!!fieldname} without the [ ] enclosing square brackets in my attempts to get it working and when I try just now it does not behave as expected. My suspicions are…

  1. I have a bug or typo somewhere.

  2. The fact that the field is set as a negative integer ( -800 although it is represented as text ) is disagreeing somehow with the way that the operator days/tiddlywiki is interpreting this, however the operator days/tiddlywiki is interpreting a literal hard coded value of -800 correctly.

Looks like I need to continue digging - thanks Jon

@jonnie45 the days operator is a little tricky to use, I attempoted to document it in the past and it never felt complete, however it may help https://groups.google.com/g/tiddlywiki/c/60yAONBAh04/m/IKd32r8GBgAJ

  • Perhaps you can set a variable?
  • Often the solution is one days operator followed by another, then using the “!” to negate but the logic kind of flips making it a little hard to read off the likely outcome.
  • See also Today, Yesterday and Tomorrow with Days Filter Operator

Thanks useful to know, at the moment I am comparing two versions of the filter one with [-800] and one with {!!fieldname} - I just did some sanity checks to make sure that these were the only differences and yes the issue persists.

This makes me suspect the negative number - does the leading minus when the value is taken from a tiddler field upset everything, this might be a bug in days - whatever the behaviour one would expect the same from equivalent parameters.

Equally well it might be that I have a typo or bug in my own code that triggers different behaviour for apparently equivalent args where there should be none.

I will play around some more.

days is a very useful operator for my purposes.

  • I don’t believe this should be a problem. If I get a chance I will check.

On tiddlywiki.com the following works when the days-old field contains -65

{{{ [days{!!days-old}!days[-1]!sort[modified]] }}}

Also

<$let days-old="-65">

{{{ [days<days-old>!days[-1]!sort[modified]] }}}

</$let>

Hi,

That would equate to a “pass” filter for dates up to 65 days ago but more than one day ago?

If I were to take the above filter and move it in the direction of my intended logic using the same interval of -65 days it would be something like this…

ie a “pass” filter for dates at least 65 days ago.

I store two fields in a tiddler the first time it is included for review - the first is the date that the tiddler was last reviewed - the second is the intended interval in days, tiddlers that are not included in the review scheme don’t have these two fields.

So when I click a “review” symbol on the tiddler tool bar…the last-reviewed3 field is created if not already present and then updated with the UTC coding of today.

<$action-setfield last-reviewed3=<<now “[UTC]YYYY0MM0DD0hh0mm0ss0XXX”>> $timestamp=“no”/>

<$list filter="[!has:field[interval3]]">
<$action-setfield interval3=-30 $timestamp=“no” />
</$list>

If the tiddler does not have an interval3 field yet then I store the default of -30; subsequent clicks on the review button will not attempt to re-initialise the interval3 value because I might have decided on a different (negative) value that suits this tiddler better.

interval3 is always stored as a negative integer.

So then at a later date when I wish to see a list of tiddlers requiring a review I can use the days operator.

<$list filter=’[all[tiddlers]!is[system]!tag[z hidden]has:field[last-reviewed3]!days:last-reviewed3{!!interval3}]’>

Which if I understand the operator days correctly should give a list of tiddlers that are overdue for a review - in the case of intval3 being -65 this would mean a list of tiddlers that have not been reviewed for 65 days.

From the days doc…

Select tiddlers where a specified date field (default “modified”) is within a specified date range.

In my case I am not using the default of ‘modified’ but instead the UTC date field named last-reviewed3 and an interval of interval3 ( negative integer ) this being the tiddler’s own review frequency expressed in days but stored as a negative integer in preparation for the logic of days argument spec.

I take this to mean that the date field ‘last-reviewed3’ is compared with today and the logic applied, in my case whether ‘last-reviewed3’ is at least 65 days in the past relative to today.

Just writing it out in full.

Hi, Is your last post just a summary, of is there still a problem?

Hi Mario - yes, there is still a problem.

Assuming there is not a quirky bug in my code the operator days does not seem to work consistently dependent on whether the parameter D is supplied as a hard coded negative number or supplied as a field in the current tiddler which has the same negative value.

https://tiddlywiki.com/static/days%20Operator.html

The following extract from a filter statement

!days:last-reviewed3[-800]

Does not give the same result as

!days:last-reviewed3{!!interval3}

Where interval3 is a UTC date field in the current tiddler that has value -800

The behaviour of the hard coded version is correct but the greater issue is that the behaviour is not consistent.

I cannot rule out a quirk in my code of course.

There are possibly=a few errors, perhaps show more of the code and explain what is broken.

  • Use [all[current]... when referring to the current tiddler eg [all[current]!has: field[interval3]]
    • That example needs a button trigger.
  • {{{ ![days<days-old>!sort[modified]] }}} should be {{{ [!days<days-old>!sort[modified]] }}}

Thanks TW_Tones, I have a feeling it might be the [all[current]] “bit” advanced apologies for my naivety if this is the case. Your comment makes me wonder if I am making an assumption about tiddler field access in filters? That would certainly make sense in view of the observed behaviour.

I am comparing the behaviour of the “hard coded” and “tiddler field coded” versions of filter in my sidebar with the following…buttons.

I am expecting the behaviour to be the same.

First the version using a tiddler field interval3 which exists in 3 test tiddlers and is set to -800

<$macrocall $name=“tag-pill” tag=“Review” element-tag="$button" actions="""<$wikify name=“filteredList” text="<$list filter=’[all[tiddlers]!is[system]!tag[z hidden]has:field[last-reviewed3]!days:last-reviewed3{!!interval3}sort[last-reviewed3]]’><$text text=’[[’/><$text text={{!!title}}/><$text text=’]] '/></$list>"><$action-setfield $tiddler="$:/StoryList" list=<>/></$wikify>"""/>

And then the version that simply uses a hard coded value of -800

<$macrocall $name=“tag-pill” tag=“Review2” element-tag="$button" actions="""<$wikify name=“filteredList” text="<$list filter=’[all[tiddlers]!is[system]!tag[z hidden]has:field[last-reviewed3]!days:last-reviewed3[-800]sort[last-reviewed3]]’><$text text=’[[’/><$text text={{!!title}}/><$text text=’]] '/></$list>"><$action-setfield $tiddler="$:/StoryList" list=<>/></$wikify>"""/>

There are a number of flaws in your code. The biggest problem is that, within the filter syntax, {!!interval3} does NOT refer to the interval3 field in each matched tiddler title. Rather, it only refers to the interval3 field in the tiddler that contains the code that is being invoked. That is why [-800] (a literal value) works as you expected, but {!!interval3} does not.

To filter based on the interval3 field from each matched tiddler title, you can use the :filter[...] filter run prefix (see https://tiddlywiki.com/#Filter%20Filter%20Run%20Prefix). This is because within the :filter[...] filter run the value of <currentTiddler> is automatically set to each tiddler title matched by the preceding filter run, so a reference to {!!interval3} will correctly refer to the desired field value from each matched tiddler, rather than the tiddler that contains the $button code.

Try this:

<$button>Review
<$action-setfield $tiddler="$:/StoryList"
   list={{{ [all[tiddlers]!is[system]!tag[z hidden]has:field[last-reviewed3]]
      :filter[!days:last-reviewed3{!!interval3}]
      +[sort[last-reviewed3]format:titlelist[]join[ ]] }}}/>
</$button>

Notes:

  • Instead of using a “tag-pill”, just use a $button widget to perform the $action-setfield that sets the current $:/StoryList!!list field. Note that in your original code, element-tag="$button" is incorrect because $button is a widget name, not an HTML element name.
  • To construct the desired $:/StoryList!!list field contents, use the “tripled curly braces” filtered transclusion syntax – {{{ [...] }}} --, like this:
    • The filter begins with [all[tiddlers]!is[system]!tag[z hidden]has:field[last-reviewed3]], which finds all tiddler titles that have a last-reviewed3 field.
    • Then, the :filter[!days:last-reviewed3{!!interval3}] filter run is applied to each matching tiddler title to select only those tiddler titles that have a last-reviewed3 date that is older than their corresponding interval3 field value.
    • Finally, instead of using $wikify and $text widgets to assemble the list of tiddler titles, the last filter run sorts the results (as you were already doing), and then uses format:titlelist[] to add doubled square brackets as needed around any titles that contain spaces, and then uses join[ ] to assemble the titles into a combined space-separated, bracketed list value.
  • This combined space-separated, bracketed list is then saved into the $:/StoryList!!list field, so that the StoryRiver contents will display all the tiddlers to be reviewed.

I hope this make sense. Let me know how it goes…

enjoy,
-e

5 Likes

Wow! thanks so much Eric, and everyone else as well of course !!! :smiley:

It passed my first few tests, I will give it a good thrashing of course but it looks good so far.

I am aiming for a fairly simple tiddler review tool so it’s unlikely I will create anything worthy of a plugin but I feel I should at least paste up the final code segments in case it’s of use to others. Would you mind your code segment being a part of that?

Much appreciated Jon