Pickaday-Plugin: Howto add date-calculation?

Sorry, I was not able to reply, I have not been online here as much in recent days. The idea that I have made use of is to keep it simple and not do any data maths, except when listing something.

So the idea is, when you create something to do it, use a now date timestamp. Think of this as actioned or created now. Lets call it last-action-stamp, If you want you could use a tag or field to indicate you want to do it every week. fortnight, month etc…

Now in a separate list, let us call it “fortnight”, you display any tiddler with say the fortnight tag, but with last-action-stamp older than 14 days, and no done tag, that it is, has not being actioned in the last 14 days (it is now due again). To do it you just mark it done by stamping last-action-stamp with now. It will leave the fortnight list, and reappear in another 14 days.

<$list filter="[all[tiddlers]tag[fourtnight]!sort[last-action-stamp]]"><!-- all fortnightly tiddlers -->
   <$list filter="[all[current]get[last-action-stamp] days test">
      <$link/><br>
   </$list>
</$list>

The above is incomplete and untested, it is just for illustration.

  • Use the days operator to only list tiddler who’s last-action-stamp is older than 14 days (since it was last done).

A key advantage is the same method can be use to list items who’s last action was older than a week (7days) month, year etc…

The key innovation with this method is the tiddler stores when it was last actioned, and one or more views will list if it was last actioned in a particular time period. You can use tags to make sure it appears in a particular list. Thus it is trivial;

  • to move the task between different lists (just change the tag)
  • to have lists containing multiple time periods
  • and much more…

@stobot ,
yes, the strange thing is, it only shows this strange behaviour in my private wiki.
I did the both tests, you said:
The 2.: The recent changed tiddlers where showing up like it should be. When choosing days, weeks, months or years, then the “otherTiddler” went to top. And then, when klicking the add-button, the “New Tiddler” (with your code) went on top, because it was the last modified one (by getting the due-field emptied).
And the 1.: Haven’t been sure what to do, I did this: Changing <$list filter="[{otherTiddler!!whattoadd}match[Days]]" variable="x"><$button actions=<<add-days>>>Add</$button></$list> to <$list filter="[[20240523]adddays[1]]" variable="x"><$button actions=<<add-days>>>Add</$button></$list>, then clicked the add-button and watched what happened. And this I did with the weeks-filter, months-filter & years-filter; one after the other. Hope, I understood it correct?
So the result was: Changing the weeks-filter, months-filter & years-filter (= 3 tests), the add-button disappeared, so I couldn’t test, if it would work.
Changing the days-filter, the add-button appeared normal, I clicked it and the due-field was edited correct >the code worked correctly. BUT: When I left this change as is and choosed weeks or months or years, then there have been 2 add-buttons!
Strange??

@TW_Tones , this sounds interesting. On one side wonderful fantastic, on the other side maybe like what I do not prefer. Or maybe it could be fantastic for only this wiki. But maybe, if I like working with my todo-list, I want to implement the same in another wiki. And there my first critical point is happening.
Like I understand it- but maybe I am wrong…:

  • In my other wiki I would have a lot of different recurrings, not only weekly, fourtnight, monthly, yearly. But additionally every 2./3./5./ day, 3./5./6./7. week and so on… Wouldn’t it be almost impossible too much different recurrings for creating this solution?
    But in this actual wiki it would be great, hitting just the last-action-stamp and only with this it recurrs correctly. Because in this actual wiki I mostly (but also not only) have yearly recurrings.
  • Is it possible not to have lists like “every 14 days”, “monthly” and so on; but instead to have separate lists “today”, “tomorrow”, “next week”, “future”, each inside a details-widget and there sorted by due-date, then by title?

Do you know a demo anywhere, where I could see it?

@Noushka in one wiki you can cater for whatever you need, tiddlywiki is like that. If you want more periods, then yes you may consider a different pattern. One case is when you want to do repetitive learning tasks.

  • For example after a lesson, review next day, next 3 days next 4 days, weekly then monthly… In this case you could define a set of steps, 1st 2nd 3rd etc… if you are at the 2nd step the next will be in 3 days( or it is due when days[-3]
  • You can use the same stamp when done method, note if not done, it stays as has to be done.
  • The main trick is to automate, so you do not need to think about when next, just now.

You can create any type or combination of lists you want, in the past I had them on the same page, at the top would be overdue, then today then this week, this month… I would just start at the top and work my way down.

Not sure of a demo, I may produce one, one day.

@TW_Tones ,

yes, of course. I had just the hope, to use the same thing in both. And with that, avoiding to ask here again… :wink:

Well, both are for ToDos. In the actual wiki most of the tasks are at a specific day, once a year.
But some of them are different, for example: Do it at 15th february, when done then repeat after 7 days >this pattern 4 times and then next year the same procedure beginning at 15th february.
Or another one: Repeat monthly, beginning 28th march, end in octobre.

I don’t know, how to integrate such tasks in your solution?

Thought a longer time about both possibilities, now I think, the solution from @stobot is the one I need for this wiki at the moment. Unfortunately it is not so wunderful automatic like that from TW_Tones :disappointed_relieved: :wink:, but I have more flexibility with it- what I need.

Now, to get it work I have another idea -a much more simple one :slight_smile: . But I need your help- please @stobot , could you please help with this idea of your solution?

My idea is: I do the math, but not inside a button or something similar. Instead only showing me, which date has to be the next due date- in 2 different ways (calculated from today & calculated from original due date). In that way, I can always decide, which date should be the next due date. Often it happens, that I am late with tasks. Some of them need to be done f.e. once a week (>calculate from today), but others need to be done f.e. once a year always on the first of february (>calculate from original due date).
But now my problem is, that both codes do not work like I want. Not for “calculate from today” and not for “calculate from original due date”:
{{{ [<dateadd>adddays[7]] }}} for calculating from today returns “18991207”,
{{{ [<now "YYYY0MM0DD">adddays[1]] }}} for calculating from today returns "20240608- correct, but not good readable for me,
{{{ [<now "DD.MM.YY">adddays[2]] }}} for calculating from today returns “NaN”, doesn’t matter how I format the date- only if it is “YYYY0MM0DD” it works correct.

And for calculating from the original due date I tried {{{ [{{!!due}}adddays[2]] }}} with different amounts & combinations of brackets & characters, like [{!!due}], {!!due}, {due},… None of them worked.

All of this I tried in my actual private wiki, in the test-wiki on tiddlyhost and in an empty new tiddlywiki.

So, how do I need to write both codes for correct working, but with another date format?

Hi @Noushka , a few things to cover here.

It’s important to know that TiddlyWiki natively stores it’s dates in a particular way, as [UTC]YYYY0MM0DD0hh0mm0ss0XXX format. Tiddlers as you create and modify them will store the current time in this format. If I create a new tiddler, click the “more” toolbar button, and choose info it looks like the below. See the long string of numbers. that goes in YYYY0MM0DD format and then keeps going for hours, minutes, seconds, and microseconds. Learn more about that format here: https://tiddlywiki.com/#DateFormat

image

So for my purpose I needed to hand key dates, but wanted to create filters that could handle both the standard dates and my own hand-keyed dates, so I settled on YYYY0MM0DD as how I’d enter my own dates. So, the filter functions expect either just YYYY0MM0DD numbers, or the full version - both work. Note though that in order to add days, you need to give it a date. Now going through your questions:

I don’t know what <dateadd>'s value is, but if it’s not recognized, then it’s treated as 0, which in javascript is 18991130. If dateadd is from the old macros I built - don’t use both - they’re probably incompatible. To add 7 days from today you should do {{{ [<now YYYY0MM0DD>adddays[7]] }}}

Second thing you need to know is that TiddlyWiki dates stored in native format can then be formatted however you want. See the link I posted above on dateformat plus the format operator https://tiddlywiki.com/#format%20Operator. So, instead of what you tried, you’d probably want something like {{{ [<now YYYY0MM0DD>adddays[1]format:date[DD.MM.YY]] }}} if that’s how you like to display your dates.

Yes, as mentioned above, the filter operators only work on standard dates or the short version, both start with YYYY0MM0DD. So, instead, again you’d want {{{ [<now YYYY0MM0DD>adddays[2]format:date[DD.MM.YY]] }}} see how you don’t format the input string, you do the math on standard date format and then format it after the date math.

Assuming the “due” is a number string in standard date format, then it will work other than the all-too-common “too many bracket” error. Many people explain it better (typically Eric), but the way I remember it is the “filter rule of 2 brackets deep”. That means if you’re ever 3 brackets deep - it’s not going to work. For this rule you have to ignore the fact that the shorthand for returning the value for a filter string is {{{ filter }}}, so don’t count those ones. But your filter string was [{{!!due}}adddays[2]] see how you do one square bracket and then 2 curly ones - that’s “3 deep” and therefore too many. In filter strings anything that’s normally 2 brackets is only 1. So [{!!due}adddays[2]] would be the right filter string, and inside the shorthand notation would be {{{ [{!!due}adddays[2]] }}}

Hope that helps, good luck!

2 Likes

Hi @stobot ,
got a while for understanding and for integrating it /getting it to work with everything I wanted. But now I got it. Thank you a lot!!! :+1: :+1: :+1:
I got it not exactly like I originally wanted- I wanted to put the calculating-buttons into a field & then to transclude these buttons in the dynamic ToDo-Table. That transcluding was not possible and then I decided, that it is even more flexible =better, to have an additional button for always being able to not only calculate from today, but also from the original due date.
So I put both calculating buttons into each Task-tiddler and then I have to expand the tiddler in the ToDo-Table.
(The perfect solution would be: Having the possibility to select if calculating from today or from due-date inside my solution, having that solution in a field of the task-tiddlers and to bring that to work in the dynamic ToDo-Table. But of this I can only dream of… :grin: and I am not in a world of dreams…).

But, what I would really like to achieve (& hope for that possibility):
To batch-edit the due-field by calculating. For example: Checking 10 tiddlers (with maybe different due-dates), choose the number- f.e. 1, choose the amount- f.e. years, and then add this “1 year” to all these 10 tiddlers.
So that tiddler A with due-date 12.06.2024
& tiddler B with due-date 05.03.2024 then get both moved to 2025:
=Ttiddler A with due-date 12.06.2025
& tiddler B with due-date 05.03.2025.

Is that possible and how to achieve that?

Edit: The Testwiki with the relevant tiddlers open for experimenting with it

1 Like

Hi @Noushka, your question appears a bit complex and specific, but I’ll try to give some general information that should let you get to the next step, though none of your questions seem to really be related to the filter operators that I pointed you to, just general TiddlyWiki concepts.

In your “perfect solution” you refer to drop downs and then applying the math based on what was selected - like days, years etc. For that, remember that you don’t have to try to figure out branching logic all within the filter operator, you’d do in in presentation of the button, such that each button only has to do one thing, but that you’d use logic to decide what button to show. That’s shown by example on my post to you earlier above that starts with “Interesting”. See the buttons within the <$list> widgets?

So conceptually, think where you need user input to do branching:

  1. Use a widget like <$select> and store the result in a tiddler (I use temp tiddlers like $:/temp/type-of-date)
  2. Selectively show contents based on the result of that temp tiddlers using <$list> widgets testing for the value of that tiddler.
  3. Within that shown content, put the <$button> and <$action-...> code that makes sense.

Batch editing of any kind is easy in TiddlyWiki because the same repeated logic you use for showing things, can just be inside an action widget triggered by a button.

So to just find with due dates, and listing them after adding a year to them would be like (untested code):

<$list filter="[has[due]]">
{{{ [get[due]addyears[1]] }}}
</$list>

While the code to instead make that into a batch edit command you’d only need to tweak it to something like (untested code):

<$button>Add Year
<$list filter="[has[due]]">
<$action-setfield $field="due" $value={{{ [get[due]addyears[1]] }}}/>
</$list>
</$button>

I think it’s useful to show the transition from “show” to “change” because there’s no undo with stuff like this, so save first, and then make sure the “show” version does what you want before you modify it.

Couple points on the batch example for the sake of completeness:

  • The list widget by defaults the currentTiddler variable, so that’s why the get[due] will dynamically grab each tiddler’s due date and add to it
  • I’m using the simpler but less perfect code pattern of having an action-widget just within a button widget. It’s recommended instead to put the everything other than the label for the button inside a procedure, and give that procedure name as a variable to the “actions” parameter of the button widget.

Hi @stobot ,
I think, thanks to your help I am not far away anymore from my goal for batch-calculating the due-dates :slight_smile: .

For the first question I combined the several possibilities in a less elegant way. I did not understand, how to do it more elegant with select- how to combine all these possibilities in the right way for filtering & adding the calculation and so on. So I put just all the possibilities into this one select-widget. Disadvantage: Looks less elegant- but this wiki is only for me, so no need for being very elegant. But with the advantage of less clicking & space-saving, which is both more important for me.

For the batch due-calculation:
I tried it now with the combined solution from before & your last answer:

<<add-days-now>><<add-weeks-now>><<add-months-now>><<add-years-now>><<add-days-due>><<add-weeks-due>><<add-months-due>><<add-years-due>>
+ <$edit-text tiddler="DueBerechnung" field="add" size="2"/>
<$select tiddler="DueBerechnung" field="whattoadd">
<option>Days v heute</option>
<option>Weeks v heute</option>
<option>Months v heute</option>
<option>Years v heute</option>
<option>Days f Due</option>
<option>Weeks f Due</option>
<option>Months f Due</option>
<option>Years f Due</option>
</$select>
<$list filter="[tag[BatchEdit]]">
<$list filter="[{DueBerechnung!!whattoadd}match[Days v heute]]" variable="x">=<$button actions=<<add-days-now>>>✓ (={{{ [<now YYYY0MM0DD>adddays{DueBerechnung!!add}format:date[DD.MM.'YY]] }}})</$button></$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Weeks v heute]]" variable="x">=<$button actions=<<add-weeks-now>>>✓ (={{{ [<now YYYY0MM0DD>addweeks{DueBerechnung!!add}format:date[DD.MM.'YY]] }}})</$button></$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Months v heute]]" variable="x">=<$button actions=<<add-months-now>>>✓ (={{{ [<now YYYY0MM0DD>addmonths{DueBerechnung!!add}format:date[DD.MM.'YY]] }}})</$button></$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Years v heute]]" variable="x">=<$button actions=<<add-years-now>>>✓ (={{{ [<now YYYY0MM0DD>addyears{DueBerechnung!!add}format:date[DD.MM.'YY]] }}})</$button></$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Days f Due]]" variable="x">=<$button actions=<<add-days-due>>>✓ (={{{ [{!!due}adddays{DueBerechnung!!add}format:date[DD.MM.'YY]] }}})</$button></$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Weeks f Due]]" variable="x">=<$button actions=<<add-weeks-due>>>✓ (={{{ [{!!due}addweeks{DueBerechnung!!add}format:date[DD.MM.'YY]] }}})</$button></$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Months f Due]]" variable="x">=<$button actions=<<add-months-due>>>✓ (={{{ [{!!due}addmonths{DueBerechnung!!add}format:date[DD.MM.'YY]] }}})</$button></$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Years f Due]]" variable="x">=<$button actions=<<add-years-due>>>✓ (={{{ [{!!due}addyears{DueBerechnung!!add}format:date[DD.MM.'YY]] }}})</$button></$list>
</$list>

<table>
<tr><th>Tiddler Name</th><th>Due-Date</th><th>New Due-Date</th></tr>
<$list filter="[tag[BatchEdit]]">
<$fieldmangler tiddler=<<currentTiddler>>>
<tr><td><$link to=<<currentTiddler>>><$view field='title'/></$link></td><td><$view field='due'  format="date" template="DD.MM.'YY"/></td><$list filter="[tag[BatchEdit]]">
<$list filter="[{DueBerechnung!!whattoadd}match[Days v heute]]" variable="x">new: {{{ [<now YYYY0MM0DD>adddays{DueBerechnung!!add}format:date[DD.MM.'YY]] }}}</$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Weeks v heute]]" variable="x">new: {{{ [<now YYYY0MM0DD>addweeks{DueBerechnung!!add}format:date[DD.MM.'YY]] }}}</$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Months v heute]]" variable="x">new: {{{ [<now YYYY0MM0DD>addmonths{DueBerechnung!!add}format:date[DD.MM.'YY]] }}}</$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Years v heute]]" variable="x">new: {{{ [<now YYYY0MM0DD>addyears{DueBerechnung!!add}format:date[DD.MM.'YY]] }}}</$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Days f Due]]" variable="x">new: {{{ [{!!due}adddays{DueBerechnung!!add}format:date[DD.MM.'YY]] }}}</$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Weeks f Due]]" variable="x">new: {{{ [{!!due}addweeks{DueBerechnung!!add}format:date[DD.MM.'YY]] }}}</$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Months f Due]]" variable="x">new: {{{ [{!!due}addmonths{DueBerechnung!!add}format:date[DD.MM.'YY]] }}}</$list>
<$list filter="[{DueBerechnung!!whattoadd}match[Years f Due]]" variable="x">new: {{{ [{!!due}addyears{DueBerechnung!!add}format:date[DD.MM.'YY]] }}}</$list>
</$list></td></tr>
</$fieldmangler>
</$list>
</table>

And this is the given result:
grafik
So, I think, I made a mistake somewhere with the <$list> & with the </td>.
Because, the filtered & listed results are listed as many times, as they are found.

What do I need to do, so that in the right column the value of the future due-date is shown?

Hello @Noushka, at first glance you have a <$list filter="[tag[BatchEdit]]"> within another one, so a loop within a loop - is that maybe the problem?