1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 02:19:55 +00:00

Update the sameday and eachday filter to accept ISO date strings. Extends coverage to fields that are not automatically converted to Date objects.

This commit is contained in:
Roma Hicks 2015-02-21 11:39:03 -06:00
parent a507d58211
commit a5591dc7a5
2 changed files with 16 additions and 2 deletions

View File

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

View File

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