1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 12:07:19 +00:00

Fix eachday and sameday filter operators

There was some inconsistency of UTC vs. timezone handling
This commit is contained in:
Jeremy Ruston 2013-09-21 10:08:16 +01:00
parent f0d459c5c5
commit f51d0c55fe
2 changed files with 17 additions and 7 deletions

View File

@ -16,6 +16,11 @@ Filter operator that selects one tiddler for each unique day covered by the spec
Export our filter function Export our filter function
*/ */
exports.eachday = function(source,operator,options) { 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 // Convert the source to an array if necessary
if(!$tw.utils.isArray(source)) { if(!$tw.utils.isArray(source)) {
var copy = []; var copy = [];
@ -25,13 +30,13 @@ exports.eachday = function(source,operator,options) {
source = copy; source = copy;
} }
// Collect up the first tiddler with each unique day value of the specified field // 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) { $tw.utils.each(source,function(title) {
var tiddler = options.wiki.getTiddler(title); var tiddler = options.wiki.getTiddler(title);
if(tiddler) { if(tiddler && tiddler.fields[operator.operand]) {
var value = tiddler.getFieldString(operator.operand).substr(0,8); var value = toDate(tiddler.fields[operator.operand]);
if(!$tw.utils.hop(values,value)) { if(values.indexOf(value) === -1) {
values[value] = true; values.push(value);
results.push(title); results.push(title);
} }
} }

View File

@ -16,12 +16,17 @@ Filter operator that selects tiddlers with a modified date field on the same day
Export our filter function Export our filter function
*/ */
exports.sameday = function(source,operator,options) { 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 to check an individual title
function checkTiddler(title) { function checkTiddler(title) {
var tiddler = options.wiki.getTiddler(title); var tiddler = options.wiki.getTiddler(title);
if(tiddler) { 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 === "!") { if(operator.prefix === "!") {
match = !match; match = !match;
} }