Help w/dates please?

96 views
Skip to first unread message

Damien Errol

unread,
Jan 17, 2021, 9:11:35 AM1/17/21
to TiddlyWiki
My tiddlywiki has a topbar where I want to display tags for today and the past week.

Every tiddler is tagged with the date it was created in the format DD-MM-YY, e.g. a tiddler created 18th January 2021 is tagged with 18-1-21.
I want to display 18-1-21, 17-1-21, 16-1-21, so on, along the top.

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. Any help would be much much appreciated. Thank you!

Javier Eduardo Rojas Romero

unread,
Jan 24, 2021, 2:05:58 PM1/24/21
to tiddl...@googlegroups.com
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

TW Tones

unread,
Jan 24, 2021, 5:10:17 PM1/24/21
to TiddlyWiki
Damien,

My first question is why tag something with information already in the tiddler, the created date instead you can use search, sort and days operators etc... to list tiddlers.

Of course if you want to sort something the something needs to be sortable. This Is why I would stay with the created date which is yyyy0mm0dd... rather than mm-dd-yyyy which your tags are, day of month 12 would come before day of month 2

What I am suggesting is you step back and define/redefine your needs because it seems to me, whist I could give you some answers, I would only be helping you go down the wrong path.

Regards
Tones

Reply all
Reply to author
Forward
0 new messages