Extend sameday operator to select field

Now the target field can be specified in the suffix:
`[sameday:created[20140808]]`
print-window-tiddler
Jermolene 2014-04-10 20:19:10 +01:00
rodzic 18d14031b7
commit ccf2cb36a1
2 zmienionych plików z 5 dodań i 3 usunięć

Wyświetl plik

@ -17,14 +17,15 @@ Export our filter function
*/
exports.sameday = function(source,operator,options) {
var results = [],
fieldName = operator.suffix || "modified",
targetDate = (new Date($tw.utils.parseDate(operator.operand))).setHours(0,0,0,0);
// Function to convert a date/time to a date integer
var isSameDay = function(dateField) {
return (new Date(dateField)).setHours(0,0,0,0) === targetDate;
};
source(function(tiddler,title) {
if(tiddler && tiddler.fields.modified) {
if(isSameDay(tiddler.fields.modified)) {
if(tiddler && tiddler.fields[fieldName]) {
if(isSameDay(tiddler.fields[fieldName])) {
results.push(title);
}
}

Wyświetl plik

@ -4,11 +4,12 @@ tags: filters
title: FilterOperator: sameday
type: text/vnd.tiddlywiki
The ''sameday'' filter operator filters the current list to leave only those tiddlers whose `modified` field is on the same day as the date provided as the operand.
The ''sameday'' filter operator filters the current list to leave only those tiddlers whose `modified` field is on the same day as the date provided as the operand. The optional suffix allows a different field to be specified.
For example:
|!Filter String |!Description |
|`[sameday[20140410]]` |Returns a list of the tiddlers modified on the 10th April 2014 |
|`[sameday:created[20140410]]` |Returns a list of the tiddlers created on the 10th April 2014 |
See [[FilterOperator: eachday]] for an example.