mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Merge #1909 from @nameanyone
This commit is contained in:
parent
7037b66479
commit
57ceffd67c
49
core/modules/filters/days.js
Normal file
49
core/modules/filters/days.js
Normal file
@ -0,0 +1,49 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/days.js
|
||||
type: application/javascript
|
||||
module-type: filteroperator
|
||||
|
||||
Filter operator that selects tiddlers with a specified date field within a specified date interval.
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter function
|
||||
*/
|
||||
exports.days = function(source,operator,options) {
|
||||
var results = [],
|
||||
fieldName = operator.suffix || "modified",
|
||||
dayInterval = (parseInt(operator.operand,10)||0),
|
||||
dayIntervalSign = $tw.utils.sign(dayInterval),
|
||||
targetTimeStamp = (new Date()).setHours(0,0,0,0) + 1000*60*60*24*dayInterval,
|
||||
isWithinDays = function(dateField) {
|
||||
var sign = $tw.utils.sign(targetTimeStamp - (new Date(dateField)).setHours(0,0,0,0));
|
||||
return sign === 0 || sign === dayIntervalSign;
|
||||
};
|
||||
|
||||
if(operator.prefix === "!") {
|
||||
source(function(tiddler,title) {
|
||||
if(tiddler && tiddler.fields[fieldName]) {
|
||||
if(!isWithinDays($tw.utils.parseDate(tiddler.fields[fieldName]))) {
|
||||
results.push(title);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
source(function(tiddler,title) {
|
||||
if(tiddler && tiddler.fields[fieldName]) {
|
||||
if(isWithinDays($tw.utils.parseDate(tiddler.fields[fieldName]))) {
|
||||
results.push(title);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
})();
|
@ -1,35 +0,0 @@
|
||||
/*\
|
||||
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),
|
||||
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;
|
||||
};
|
||||
|
||||
})();
|
@ -643,4 +643,15 @@ exports.tagToCssSelector = function(tagName) {
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
IE does not have sign function
|
||||
*/
|
||||
exports.sign = Math.sign || function(x) {
|
||||
x = +x; // convert to a number
|
||||
if (x === 0 || isNaN(x)) {
|
||||
return x;
|
||||
}
|
||||
return x > 0 ? 1 : -1;
|
||||
};
|
||||
|
||||
})();
|
||||
|
16
editions/prerelease/tiddlers/staging/filters/days.tid
Normal file
16
editions/prerelease/tiddlers/staging/filters/days.tid
Normal file
@ -0,0 +1,16 @@
|
||||
tags: [[Filter Operators]] [[Date Operators]] [[Negatable Operators]]
|
||||
title: days Operator
|
||||
type: text/vnd.tiddlywiki
|
||||
caption: days
|
||||
op-input: a [[selection of titles|Title Selection]]
|
||||
op-neg-output: those input tiddlers in which field <<.place F>> is more than <<.place D>> days in the { future | past }, where <<.place D>> is { positive | negative }
|
||||
op-output: those input tiddlers in which field <<.place F>> is <<.place D>> days in the { future | past } or any time { before | after } that, including { past | future }, where <<.place D>> is { positive | negative }
|
||||
op-parameter: a number of days, defaulting to 0
|
||||
op-parameter-name: D
|
||||
op-purpose: filter the input by date
|
||||
op-suffix: the name of a [[date field|Date Fields]], defaulting to <<.field modified>>
|
||||
op-suffix-name: F
|
||||
|
||||
Select tiddlers where a specified date field (default "modified") is withing a specified date range. Time portion is ignored.
|
||||
|
||||
<<.operator-examples "days">>
|
@ -1,9 +1,9 @@
|
||||
tags: [[recent Operator]] [[Operator Examples]]
|
||||
title: recent Operator (Examples)
|
||||
tags: [[Operator Examples]] [[days Operator]]
|
||||
title: days 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">>
|
||||
<<.operator-example 1 "[days[-14]]" "tiddlers modified within the last 14 days">>
|
||||
<<.operator-example 2 "[!days:created[-800]]" "tiddlers created more than 800 days ago">>
|
||||
The filter can be used to highlight new items in a list. For example:
|
||||
<$macrocall
|
||||
$name="wikitext-example-without-html" src=
|
||||
@ -11,7 +11,7 @@ The filter can be used to highlight new items in a list. For example:
|
||||
<ul>
|
||||
<$list filter="[tag[ReleaseNotes]!<currentTiddler>!sort[modified]]">
|
||||
<li>
|
||||
<$link><$view field="title"/></$link><$list filter="[<currentTiddler>recent[90]]"> @@color:red;^^new^^@@</$list>
|
||||
<$link><$view field="title"/></$link><$list filter="[<currentTiddler>days[-120]]"> @@color:red;^^new^^@@</$list>
|
||||
</li>
|
||||
</$list>
|
||||
</ul>
|
@ -1,15 +0,0 @@
|
||||
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">>
|
Loading…
Reference in New Issue
Block a user