1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-01 01:33:16 +00:00
TiddlyWiki5/core/modules/filters/eachday.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

/*\
title: $:/core/modules/filters/eachday.js
type: application/javascript
module-type: filteroperator
Filter operator that selects one tiddler for each unique day covered by the specified date field
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.eachday = function(source,operator,options) {
var results = [],
2015-02-10 16:21:53 +00:00
values = [],
fieldName = operator.operand || "modified";
// Function to convert a date/time to a date integer
var toDate = function(value) {
value = (new Date(value)).setHours(0,0,0,0);
return value+0;
};
// Convert ISO date string to Date object if needed.
var toDateObj = function(value) {
if(!(value instanceof Date)) {
value = new Date($tw.utils.parseDate(value));
}
return value;
};
source(function(tiddler,title) {
2015-02-10 16:21:53 +00:00
if(tiddler && tiddler.fields[fieldName]) {
var value = toDate(toDateObj(tiddler.fields[fieldName]));
if(values.indexOf(value) === -1) {
values.push(value);
results.push(title);
}
}
});
return results;
};
})();