mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Format filter to create formatted date strings (#4785)
* asdate filter to create formatted date strings * Added format filter operator
This commit is contained in:
parent
bdaf3a4502
commit
72c07a3f81
@ -27,6 +27,7 @@ Error/EditConflict: File changed on server
|
|||||||
Error/Filter: Filter error
|
Error/Filter: Filter error
|
||||||
Error/FilterSyntax: Syntax error in filter expression
|
Error/FilterSyntax: Syntax error in filter expression
|
||||||
Error/IsFilterOperator: Filter Error: Unknown operand for the 'is' filter operator
|
Error/IsFilterOperator: Filter Error: Unknown operand for the 'is' filter operator
|
||||||
|
Error/FormatFilterOperator: Filter Error: Unknown suffix for the 'format' filter operator
|
||||||
Error/LoadingPluginLibrary: Error loading plugin library
|
Error/LoadingPluginLibrary: Error loading plugin library
|
||||||
Error/NetworkErrorAlert: `<h2>''Network Error''</h2>It looks like the connection to the server has been lost. This may indicate a problem with your network connection. Please attempt to restore network connectivity before continuing.<br><br>''Any unsaved changes will be automatically synchronised when connectivity is restored''.`
|
Error/NetworkErrorAlert: `<h2>''Network Error''</h2>It looks like the connection to the server has been lost. This may indicate a problem with your network connection. Please attempt to restore network connectivity before continuing.<br><br>''Any unsaved changes will be automatically synchronised when connectivity is restored''.`
|
||||||
Error/RecursiveTransclusion: Recursive transclusion error in transclude widget
|
Error/RecursiveTransclusion: Recursive transclusion error in transclude widget
|
||||||
|
46
core/modules/filters/format.js
Normal file
46
core/modules/filters/format.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/filters/format.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: filteroperator
|
||||||
|
Filter operator for formatting strings
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var formatFilterOperators;
|
||||||
|
|
||||||
|
function getFormatFilterOperators() {
|
||||||
|
if(!formatFilterOperators) {
|
||||||
|
formatFilterOperators = {};
|
||||||
|
$tw.modules.applyMethods("formatfilteroperator",formatFilterOperators);
|
||||||
|
}
|
||||||
|
return formatFilterOperators;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Export our filter function
|
||||||
|
*/
|
||||||
|
exports.format = function(source,operator,options) {
|
||||||
|
// Dispatch to the correct formatfilteroperator
|
||||||
|
var formatFilterOperators = getFormatFilterOperators();
|
||||||
|
if(operator.suffix) {
|
||||||
|
var formatFilterOperator = formatFilterOperators[operator.suffix];
|
||||||
|
if(formatFilterOperator) {
|
||||||
|
return formatFilterOperator(source,operator.operand,options);
|
||||||
|
} else {
|
||||||
|
return [$tw.language.getString("Error/FormatFilterOperator")];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Return all unchanged if the suffix is missing
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
results.push(title);
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
26
core/modules/filters/format/date.js
Normal file
26
core/modules/filters/format/date.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/filters/format/date.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: formatfilteroperator
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Export our filter function
|
||||||
|
*/
|
||||||
|
exports.date = function(source,operand,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
var value = $tw.utils.parseDate(title);
|
||||||
|
if(value && $tw.utils.isDate(value) && value.toString() !== "Invalid Date") {
|
||||||
|
results.push($tw.utils.formatDateString(value,operand || "YYYY MM DD 0hh:0mm"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
26
core/modules/filters/format/relativedate.js
Normal file
26
core/modules/filters/format/relativedate.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/filters/format/relativedate.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: formatfilteroperator
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/*
|
||||||
|
Export our filter function
|
||||||
|
*/
|
||||||
|
exports.relativedate = function(source,operand,options) {
|
||||||
|
var results = [];
|
||||||
|
source(function(tiddler,title) {
|
||||||
|
var value = $tw.utils.parseDate(title);
|
||||||
|
if(value && $tw.utils.isDate(value) && value.toString() !== "Invalid Date") {
|
||||||
|
results.push($tw.utils.getRelativeDate((new Date()) - (new Date(value))).description);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return results;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user