diff --git a/core/modules/filters/eachday.js b/core/modules/filters/eachday.js index dae0f26af..f96d9d977 100644 --- a/core/modules/filters/eachday.js +++ b/core/modules/filters/eachday.js @@ -16,6 +16,11 @@ Filter operator that selects one tiddler for each unique day covered by the spec Export our filter function */ exports.eachday = function(source,operator,options) { + // 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 the source to an array if necessary if(!$tw.utils.isArray(source)) { var copy = []; @@ -25,13 +30,13 @@ exports.eachday = function(source,operator,options) { source = copy; } // Collect up the first tiddler with each unique day value of the specified field - var results = [],values = {}; + var results = [],values = []; $tw.utils.each(source,function(title) { var tiddler = options.wiki.getTiddler(title); - if(tiddler) { - var value = tiddler.getFieldString(operator.operand).substr(0,8); - if(!$tw.utils.hop(values,value)) { - values[value] = true; + if(tiddler && tiddler.fields[operator.operand]) { + var value = toDate(tiddler.fields[operator.operand]); + if(values.indexOf(value) === -1) { + values.push(value); results.push(title); } } diff --git a/core/modules/filters/sameday.js b/core/modules/filters/sameday.js index a613a338c..bdacf733c 100644 --- a/core/modules/filters/sameday.js +++ b/core/modules/filters/sameday.js @@ -16,12 +16,17 @@ Filter operator that selects tiddlers with a modified date field on the same day Export our filter function */ exports.sameday = function(source,operator,options) { - var results = []; + var results = [], + isSameDay = function(dateField,dateString) { + var date1 = (new Date(dateField)).setHours(0,0,0,0), + date2 = (new Date($tw.utils.parseDate(dateString))).setHours(0,0,0,0); + return date1 === date2; + }; // Function to check an individual title function checkTiddler(title) { var tiddler = options.wiki.getTiddler(title); if(tiddler) { - var match = tiddler.getFieldString("modified").substr(0,8) === operator.operand.substr(0,8); + var match = isSameDay(tiddler.fields.modified,operator.operand); if(operator.prefix === "!") { match = !match; }