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.
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.
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.
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”.
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.
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
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]]'>>
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”.
/*\
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;
};
})();
Examples (after the patch)
today: <<list-links '[days:due[]]'>>