Merge #1909 from @nameanyone

This commit is contained in:
Jermolene
2015-12-23 12:19:47 +00:00
parent 7037b66479
commit 57ceffd67c
6 changed files with 81 additions and 55 deletions

View 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;
};
})();

View File

@@ -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;
};
})();

View File

@@ -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;
};
})();