[tw] [TW5] Hours Filter - as a counterpart to the Days Filter (suggestion)

2017-03-16 Thread Thomas Elmiger
Hi The Bo

I have at least one time been thinking about using such a filter – but I don't 
remember where it was … will try your solution when I stumble upon it again. 

Thanks for sharing!
Thomas 

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/f379b215-9e36-4a6c-8227-d701c2ecbefb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[tw] [TW5] Hours Filter - as a counterpart to the Days Filter (suggestion)

2017-03-16 Thread The Bo
Hey guys,

I was thinking about a hours filter which is working same like the days 
filter to show tiddlers I created or modified the last x hours.
It was quite simple to change some parts of the days core filter. So I want 
to share my result:


$:/core/modules/filters/hours.js

/*\
title: $:/core/modules/filters/hours.js
type: application/javascript
module-type: filteroperator

Filter operator that selects tiddlers with a specified date field within a 
specified hour interval.

\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Export our filter function
*/
exports.hours = function(source,operator,options) {
var results = [],
fieldName = operator.suffix || "modified",
hourInterval = (parseInt(operator.operand,10)||0),
hourIntervalSign = $tw.utils.sign(hourInterval),
targetTimeStamp = (new Date()).setMinutes(0,0,0) + 
1000*60*60*hourInterval,
isWithinHours = function(dateField) {
var sign = $tw.utils.sign(targetTimeStamp - (new 
Date(dateField)).setMinutes(0,0,0));
return sign === 0 || sign === hourIntervalSign;
};

if(operator.prefix === "!") {
targetTimeStamp = targetTimeStamp - 1000*60*60*hourIntervalSign;
source(function(tiddler,title) {
if(tiddler && tiddler.fields[fieldName]) {

if(!isWithinDays($tw.utils.parseDate(tiddler.fields[fieldName]))) {
results.push(title);
}
}
});
} else {
source(function(tiddler,title) {
if(tiddler && tiddler.fields[fieldName]) {

if(isWithinHours($tw.utils.parseDate(tiddler.fields[fieldName]))) {
results.push(title);
}
}
});
}
return results;
};

})();

type: application/javascript
module-type: filteroperator


Usage:
e.g. [hours[-2]]

Is there a need for this filter? Are there any suggestions?

Regards,
The Bo

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/67cb3389-ce6e-47c0-9176-7ad5f8e2d172%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.