Hello List,
I am using Stephan's (Skeeve) NewTiddler macro with his dateTime macro to
create a new tiddler with a date in the title and some predefined text. It
works really well, except when the the predefined text has double s in is
(like session). Then the ss becomes replaced with the seconds.
To avoid this, I have modified the dateTime macro a bit to accept a text
string including a keyword to replace:
The original function:
exports.run = function(format, ts) {
if(!ts) {
ts = new Date;
}
else {
ts = $tw.utils.parseDate(ts);
}
if(!format)
format = "YYYY-0MM-0DD 0hh:0mm:0ss";
return $tw.utils.formatDateString(ts, format);
};
My modified function:
exports.run = function(format, text, rep, ts) {
if(!rep){
rep = "<<replace>>";
}
if(!text){
text = rep
}
if(!ts) {
ts = new Date;
}
else {
ts = $tw.utils.parseDate(ts);
}
if(!format){
format = "YYYY-0MM-0DD 0hh:0mm:0ss";
}
var ds = $tw.utils.formatDateString(ts, format);
var re = new RegExp(rep, 'g');
return text.replace(re, ds);
};
The call can be the same as always:
<<dateTime>>
<<dateTime "YYYY-0MM-0DD 0hh:0mm:0ss">>
New possibility is
<<dateTime "YYYY-0MM-0DD 0hh:0mm:0ss" "Defined title <<replace>> with
dateTime">>
<<dateTime "YYYY-0MM-0DD 0hh:0mm:0ss" "Defined title replaceThis with
dateTime" "replaceThis">>
Hope this is useful to someone else.
Cheers,
Ulrik
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.