From a5591dc7a5b1612786ed4c0a5c6e864b022aaff7 Mon Sep 17 00:00:00 2001 From: Roma Hicks Date: Sat, 21 Feb 2015 11:39:03 -0600 Subject: [PATCH] Update the sameday and eachday filter to accept ISO date strings. Extends coverage to fields that are not automatically converted to Date objects. --- core/modules/filters/eachday.js | 9 ++++++++- core/modules/filters/sameday.js | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/modules/filters/eachday.js b/core/modules/filters/eachday.js index 350830564..27a20ec3d 100644 --- a/core/modules/filters/eachday.js +++ b/core/modules/filters/eachday.js @@ -24,9 +24,16 @@ exports.eachday = function(source,operator,options) { 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) { if(tiddler && tiddler.fields[fieldName]) { - var value = toDate(tiddler.fields[fieldName]); + var value = toDate(toDateObj(tiddler.fields[fieldName])); 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 478f56c90..c97f6c2f2 100644 --- a/core/modules/filters/sameday.js +++ b/core/modules/filters/sameday.js @@ -23,9 +23,16 @@ exports.sameday = function(source,operator,options) { var isSameDay = function(dateField) { return (new Date(dateField)).setHours(0,0,0,0) === targetDate; }; + // 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) { if(tiddler && tiddler.fields[fieldName]) { - if(isSameDay(tiddler.fields[fieldName])) { + if(isSameDay(toDateObj(tiddler.fields[fieldName]))) { results.push(title); } }