mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-09-19 08:10:44 +00:00
Add the timestamp suffix to the format operator (#7292)
* Create timestamp.js Taken verbatim from @ericshulman. * Add description of the timestamp suffix * Add an example for timestamp use I also snuck it a couple of cosmetic corrections, because I was too lazy to open a new PR. 😢 * Correct example 4 to use the right date formats * Correct description of the default date format * Add a test for the timestamp suffix * Add more format:timestamp tests * Drop invalid input * Update version tag in docs --------- Co-authored-by: jeremy@jermolene.com <jeremy@jermolene.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/*\
|
||||
title: $:/core/modules/filters/format/timestamp.js
|
||||
type: application/javascript
|
||||
module-type: formatfilteroperator
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
Export our filter function
|
||||
*/
|
||||
exports.timestamp = function(source,operand,options) {
|
||||
var results = [];
|
||||
source(function(tiddler,title) {
|
||||
if (title.match(/^-?\d+$/)) {
|
||||
var value = new Date(Number(title));
|
||||
results.push($tw.utils.formatDateString(value,operand || "[UTC]YYYY0MM0DD0hh0mm0ss0XXX"));
|
||||
}
|
||||
});
|
||||
return results;
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user