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:
parent
f0d459c5c5
commit
f51d0c55fe
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user