How to derive future dates from <<now>> macro?

84 views
Skip to first unread message

Jeff Vance

unread,
Oct 10, 2018, 6:48:25 PM10/10/18
to TiddlyWiki
I've been using the <<now>> macro to get current dates, year, week number, etc.  I'm now facing a situation where I have to anticipate what *next* week is going to be, based on the current week number.  I spent a lot of time trying to figure out if it's possible and nothing is coming to mind. I can get the current week number, but how would I increment it by 1?  Or how to get next year?

TonyM

unread,
Oct 11, 2018, 12:51:27 AM10/11/18
to TiddlyWiki
Jeff,

Increment by one and similar operations is most easily achieved using Evans Formula plugin (Which includes date handling) or others that use the maths.js library.

I am lobbying for such increments and item counts to be in the core, soon we will have the range operator that will help in some cases, but dates are another matter

You may increment a week number but of course a week number greater than 52? will most likely be invalid. that is the problem with date handling. Every value needs to be reset and don't tell me about days in the month or leap years/centuries.

If the tiddlers have VALID date fields, with future dates, perhaps populated by the Pickaday plugin, you can use the days operator to find them and once you have that date you can use the view widget to format date to extract the week number.

Regards
Tony

Jeff Vance

unread,
Oct 11, 2018, 11:22:39 AM10/11/18
to tiddl...@googlegroups.com
Hi Tony,

Thanks for the pointer to the plugins. After thinking about it, I'm actually tempted to just create a dictionary tiddler that serves as a lookup table for incrementing each week. It only requires 52 entries. That also takes care of the wrap around to 1. Entry 52 can just list 1 as it's increment.  I could do it for year too (maybe up to 10 years, then stop).  On one hand it seems kind of silly to use a lookup table to perform addition by 1, but in this case it seems it will get the job done with minimal fuss.

Jeff



Mark S.

unread,
Oct 11, 2018, 11:39:54 AM10/11/18
to TiddlyWiki
You can also create a macro and find the next in a series of values using the "after" operator:

\define nextweek(thisweek) <$list filter="01 02 03 04 05 06 07 08 +[after[$thisweek$]]"/>

<<nextweek "02">>

-- Mark

Mohammad

unread,
Oct 11, 2018, 12:01:20 PM10/11/18
to TiddlyWiki
Mark,

 Why don't use of range operator? look at: https://tiddlywiki.com/prerelease/#range%20Operator

This is equivalent to your code. Here you can set the upper range a big number like the last week number: 52

\define nextweek2(thisweek) <$list filter="[range[1,8,1]addprefix[0]] +[after[$thisweek$]]"/>

-Mohammad

Jeff Vance

unread,
Oct 11, 2018, 12:56:07 PM10/11/18
to TiddlyWiki

Great!  I like this idea even more.  But I'm running into a problem. Say you create the entire list, including the wrap around from 52 to 01.  Now "01" is in the list twice.  The macro works for all cases except for 01 as the input. It must see that as the last entry in the list rather than the first, and returns nothing since it is last.

Mohammad

unread,
Oct 11, 2018, 1:06:29 PM10/11/18
to tiddl...@googlegroups.com
Jeff,
 Do you mean when you wrap around and pass 52 as the input you expect to have week 1? Am I right?
If so, you need to use emptyMessage attribute!

\define nextweek2(thisweek) <$list filter="[range[1,52,1]after[$thisweek$]]" emptyMessage="1"/>

This code do the job! but if you pass the wrong week number like 53 or -1 then it again return 1. Anyway for correct input you get correct output!

-Mohammad

Jeff Vance

unread,
Oct 12, 2018, 6:04:47 PM10/12/18
to TiddlyWiki
Hi Mohammad,

Yes, that's exactly what I needed!  Thanks! I tested it and it's working now.

Cheers,
Jeff





Reply all
Reply to author
Forward
0 new messages