Filter tiddlers by date: today and in the past

1,055 views
Skip to first unread message

Julian Kniephoff

unread,
Mar 7, 2016, 7:48:09 AM3/7/16
to TiddlyWiki
I was playing around with the days filter today and noticed that there is no obvious way to make it "let through" only those tiddlers with the current date or a date in the past in the specified date field.

[days:datefield[0]] or simply [days:datefield[]] really only returns the tiddlers with the current date ih datefield as opposed to "everything before n days from now", as [days:datefield[n]] does for positive n.

Getting all tiddlers from today or in the future is equally impossible I think.

Any thoughts/workarounds? Or am I doing something wrong?

CL

unread,
Mar 7, 2016, 12:19:29 PM3/7/16
to TiddlyWiki
I haven't fully understood what you mean but I think this question is same question as mine.
Check the link to see if that's what you want.

2016년 3월 7일 월요일 오후 9시 48분 9초 UTC+9, Julian Kniephoff 님의 말:

Julian Kniephoff

unread,
Mar 8, 2016, 4:48:14 AM3/8/16
to TiddlyWiki
Yeah, it's definitely related and it at least shows me that I am not just using days wrong. Your hotfix has the problem, as you yourself noted in the other thread, that it breaks other use cases of the operator, so I just went ahead and wrote my own filters for the use cases "everything with a certain date field set to today and in the past/future". You can find them here if you are interested. (Disclaimer: It is work in progress and I am by no means an expert in TiddlyWiki plugin authoring.)

CL

unread,
Mar 8, 2016, 5:20:06 AM3/8/16
to TiddlyWiki
Thank you for sharing your TW-dating code!
I am end-user who does not really know how to code. My hotfix was best I could do :)
Those new filters look promsing. However I coudn't figure out how to use your filter. I want to ask,
  • Does this filter take suffix for name of date field like days operator?
  • Does this filter take integer as parameter?
  • Is there any other documentation for instruction?
I would be super nice if you could make that into tiddler and attach as .tid file or
you could put it in wiki file and attach wiki file here so people can simply drag and drop the tiddlers

Julian Kniephoff

unread,
Mar 12, 2016, 10:54:25 AM3/12/16
to TiddlyWiki
Sorry for the late reply, I was trying to figure out the best way to share this, but I didn't have that much time on my hands, so I'm just going to attach the js files; you should still be able to just drag and drop them into your TiddlyWiki.

To answer your questions:
  • The two filters take the field they are operating on as their operand. So to get everything that is scheduled today or in the past, you would write [past[scheduled]].
  • The filters don't take any other arguments, i.e. they also don't use the suffix. They do however work with the usual ! prefix: [!past[scheduled]] should give you everything that is scheduled in the future, explicitly excluding today.
  • Unfortunately at this point there is no documentation other than this post.

Note that these filters only handle the cases that can't be done with days, hence the lack of further flexibility (taking integer arguments and the like). Specifically these are: Get everything with a given date field set in the past/future including/excluding today. You will still have to use days to achieve any other configuration.

past.js
future.js

Rustem

unread,
Apr 6, 2016, 4:54:00 AM4/6/16
to tiddl...@googlegroups.com

Hi,

I authored the days filter operator. Haven’t been here for a while, and came back to find several threads all revolving around more or less the same thing - an inability to produce a range of days that ends yesterday (past days) or starts tomorrow (days in the future). I submitted a patch #2364 to address the issue. Following is a description of the days filter operator, most of it is applicable now, but cases involving a start day of tomorrow or an end day of yesterday will only be possible after the patch.

Parameter

The parameter (let’s call it D) is a number of days from today. It marks a begining or an end of a time interval. 0 is today only. 1 is tomorrow and everything before, -1 is yesterday and everything after, etc.

Suffix

3 days in the future may not make sense for a field like “modified”. That’s where the suffix comes in handy.
Say you have a field “due” in your tiddlers. days:due[3] will return tiddlers that are due within 3 days from today, and all past due.

Note: TiddlyWiki always uses UTC. If you are populating your date field by hand, keep that in mind. Although the exact time does not matter, since days operates with whole days, it’s important to know what hour your midnight falls on in UTC. Say, you put “20160410” in your date field. That’s Apr 10 00:00 UTC. If you are in Pacific time zone, that’s actually Apr 9 5:00 PM. If you want your date to be Apr 10, you need to enter a time between “201604100700” and “201604110659”.

Negation (logical NOT)

This is where the patch will change the behavior a bit.

If days:due[3] is everything that is due within the next 3 days, then, strictly speaking, !days:due[3] should mean anything that is NOT due due within the next 3 days, or , in other words, anything that is due in 4 days or more. That’s how the operator works now, and that makes it impossible to specify a period starting tomorrow or ending yesterday, since !days:due[1] means “due in 2 days or more”, and !days:due[-1] means “was due 2 days ago or before”.

After the patch, !days:due[1] will mean anything that is due in 1 days or more, !days:due[-1] will mean anything that was due yesterday or before.

Specifying a range of days (finite number of days)

Everything we’ve looked at so far was open-ended intervals. To get a closed interval, you simply combine two days operator steps in a filter run, and sometimes add a third one in a filter expression

Examples (after the patch)

today:
<<list-links '[days:due[]]'>>
4 days ago:
<<list-links '[days:due[-4]!days:due[-4]]'>>
<<list-links '[days:due[-4]] -[days:due[-3]]'>>
last 5 days:
<<list-links '[days:due[-5]!days:due[-1]sort[due]]'>>
next 5 days:
<<list-links '[!days:due[1]days:due[5]sort[due]]'>>
day before yesterday:
<<list-links '[days:due[-2]] -[days:due[-1]]'>>
yesterday:
<<list-links '[days:due[-1]] -[days:due[]] -[!days:due[1]]'>>
<<list-links '[days:due[-1]!days:due[-1]]'>>
tomorrow:
<<list-links '[!days:due[1]days:due[1]]'>>
<<list-links '[!days:due[1]] -[!days:due[2]]'>>
day after tomorrow:
<<list-links '[!days:due[2]] -[!days:due[3]]'>>

Arkady Grudzinsky

unread,
Apr 7, 2016, 1:37:09 PM4/7/16
to TiddlyWiki


On Wednesday, April 6, 2016 at 1:54:00 AM UTC-7, Rustem wrote:

Note: TiddlyWiki always uses UTC. If you are populating your date field by hand, keep that in mind. Although the exact time does not matter, since days operates with whole days, it’s important to know what hour your midnight falls on in UTC. Say, you put “20160410” in your date field. That’s Apr 10 00:00 UTC. If you are in Pacific time zone, that’s actually Apr 9 5:00 PM. If you want your date to be Apr 10, you need to enter a time between “201604100700” and “201604110659”.

Want to share this excellent plugin to set date fields http://kixam.github.io/TW5-datePicker/

The author has fixed the UTC problem at my request and added the ability to set the time as well.  Using this plug-in, you can set the local date and time, and it will set the field of your choice to UTC corresponding to your input.

Also, if you need a simple filter that would return "TRUE" for a date field in the past and "FALSE" for the date fields in the future (including the time), you can use the code below.  This is a stripped-down days.js, but without any arguments - just comparison to Date().


/*\
  title: $:/core/modules/filters/passed.js
  type: application/javascript
  module-type: filteroperator


  Filter operator that selects tiddlers with a specified date field in the past.


  \*/

(function(){


   
/*jslint node: true, browser: true */
   
/*global $tw: false */
   
"use strict";


   
/*
      Export our filter function
    */

    exports
.passed = function(source,operator,options) {
 
var results = [],
     fieldName
= operator.suffix || "modified",
     isInThePast
= function(dateField) {
 
return new Date(dateField) < new Date();
     
};


 
if(operator.prefix === "!") {
     source
(function(tiddler,title) {
 
if(tiddler && tiddler.fields[fieldName]) {
     
if(!isInThePast($tw.utils.parseDate(tiddler.fields[fieldName]))) {
 results
.push(title);
     
}
 
}
     
});
 
} else {
     source
(function(tiddler,title) {
 
if(tiddler && tiddler.fields[fieldName]) {
     
if(isInThePast($tw.utils.parseDate(tiddler.fields[fieldName]))) {
 results
.push(title);
     
}
 
}
     
});
 
}
 
return results;
   
};


})();

Arkady Grudzinsky

unread,
Apr 7, 2016, 1:42:30 PM4/7/16
to TiddlyWiki


On Wednesday, April 6, 2016 at 1:54:00 AM UTC-7, Rustem wrote:

Examples (after the patch)

today:
<<list-links '[days:due[]]'>>


Does this include the dates in the past as well?  My problem with your code was that if used with an argument, the filter returned an open-ended interval, but when the argument was 0, it returned strictly the same-day dates.  No past or future dates were included.  I had to set my due dates a day in the future or a day in the past to circumvent this issue and ended up stripping down your code to get my simple filter.
Reply all
Reply to author
Forward
0 new messages