mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-19 18:59:42 +00:00
ccf2cb36a1
Now the target field can be specified in the suffix: `[sameday:created[20140808]]`
37 lines
893 B
JavaScript
37 lines
893 B
JavaScript
/*\
|
|
title: $:/core/modules/filters/sameday.js
|
|
type: application/javascript
|
|
module-type: filteroperator
|
|
|
|
Filter operator that selects tiddlers with a modified date field on the same day as the provided value.
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
/*
|
|
Export our filter function
|
|
*/
|
|
exports.sameday = function(source,operator,options) {
|
|
var results = [],
|
|
fieldName = operator.suffix || "modified",
|
|
targetDate = (new Date($tw.utils.parseDate(operator.operand))).setHours(0,0,0,0);
|
|
// Function to convert a date/time to a date integer
|
|
var isSameDay = function(dateField) {
|
|
return (new Date(dateField)).setHours(0,0,0,0) === targetDate;
|
|
};
|
|
source(function(tiddler,title) {
|
|
if(tiddler && tiddler.fields[fieldName]) {
|
|
if(isSameDay(tiddler.fields[fieldName])) {
|
|
results.push(title);
|
|
}
|
|
}
|
|
});
|
|
return results;
|
|
};
|
|
|
|
})();
|