On Sun, Jan 17, 2021 at 05:55:53AM -0800, Damien Errol wrote:
> I've managed to display today's tag with a very simple:
> "
> <$vars date=<<now "DD-MM-YY">> >
> <<tag $(date)$ >>
> "
> - but I don't really know what I'm doing and I'm struggling to display
> yesterday's or the day before's date.
Tiddlywiki doesn't seem to have a ready-to-use facility for doing what
you want. So, just for testing/playing around, I adjusted the `now`
macro in one of my wikis, to allow it to take an optional offset in
days. After doing that, I can write:
<$vars date=<<now "DD-MM-YY" 8>> >
<<tag $(date)$ >>
and get 1-2-21 (8 days from now). The offset can also be negative:
<$vars date=<<now "DD-MM-YY" -3>> >
<<tag $(date)$ >>
gives me 21-1-21.
Now, I managed to do that by modifying one of the core tiddlers, and I
don't know if the way I did that is the proper one, especially
considering future upgrades to tiddlywiki. So, as a sidenote/question to
more experienced tiddlywiki plugin writers here: is there a cleaner way of
making this change (extending the `now` macro, or in general allowing
basic date arithmetic via a macro)?
Damien, I suggest you don't use my suggestion/solution immediately, but
instead wait a couple of days to see if other people can suggest a
better way of applying this change to tiddlywiki.
That said... to do the same change in your wiki, open the advanced
search, and search for the shadow tiddler $:/core/modules/macros/now.js
; then:
* make a backup of your wiki
* edit that tiddler, to modify the exports.param and exports.run
declarations; the new content is as follows:
/////////////////////////////////////////////////////////////////////////////////
exports.params = [
{name: "format"},
{name: "offset_days"}
];
/*
Run the macro
*/
exports.run = function(format, offset_days) {
var d = new Date();
offset_days = Number(offset_days);
if (offset_days) {
d.setDate(d.getDate() + offset_days);
}
return $tw.utils.formatDateString(d,format || "0hh:0mm, Ddth MMM YYYY");
};
/////////////////////////////////////////////////////////////////////////////////
* save the changes to your tiddler, save your wiki, and reload the page in the
browser.
After doing that, you'll be able to pass that new parameter to the `now`
macro as I showed in the examples in this email.
Cheers,
--
Javier Rojas
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/YA3FC8WarWOBgHp%2B%40alamut.home.org.