1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

Merge pull request #1863 from nameanyone/master

New filter "recent"
This commit is contained in:
Jeremy Ruston 2015-07-05 18:04:05 +01:00
commit c4397792f5
3 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,35 @@
/*\
title: $:/core/modules/filters/recent.js
type: application/javascript
module-type: filteroperator
Filter operator that selects tiddlers with a specified date field within the last N days.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.recent = function(source,operator,options) {
var results = [],
fieldName = operator.suffix || "modified",
targetTimeStamp = (new Date()).setHours(0,0,0,0) - 1000*60*60*24*(parseInt(operator.operand,10)||0);
var isRecent = function(dateField) {
return targetTimeStamp <= (new Date(dateField)).setHours(0,0,0,0);
};
source(function(tiddler,title) {
if(tiddler && tiddler.fields[fieldName]) {
if(isRecent($tw.utils.parseDate(tiddler.fields[fieldName]))) {
results.push(title);
}
}
});
return results;
};
})();

View File

@ -0,0 +1,6 @@
tags: [[recent Operator]] [[Operator Examples]]
title: recent Operator (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 "[recent[1]]" "tiddlers modified yesterday and today">>
<<.operator-example 2 "[recent:created[14]]" "tiddlers created within the last 14 days">>

View File

@ -0,0 +1,15 @@
tags: [[Filter Operators]] [[Date Operators]]
title: recent Operator
type: text/vnd.tiddlywiki
caption: recent
op-purpose: filter the input by age
op-input: a [[selection of titles|Title Selection]]
op-suffix: the name of a [[date field|Date Fields]], defaulting to <<.field modified>>
op-suffix-name: F
op-parameter: a number of days, defaulting to 0
op-parameter-name: D
op-output: those input tiddlers in which field <<.place F>> is at most <<.place D>> days old, ignoring time
Select tiddlers where a specified date field (default "modified") is within the last N days (default 0, meaning today).
<<.operator-examples "recent">>