Pickaday-Plugin: Howto add date-calculation?

Hello @all,

trying to build a ToDo-Manager inside TW, I tried ToDoNow from Telmiger, but had to give it up. The related threads are: How to adjust ToDoNow? & ToDoNow: How to include a calculation of due-dates?
Now I choosed https://kookma.github.io/TW-Pikaday/ . The ToDo-List inside there also almost fits my needs.

But I need additionally a calculation of due-dates (f.e. add 1 year or 14 days), which is useable inside the ToDo-list.
Mostly I need the calculation from “today” (=<<now>>), but sometimes also from the original due-date.
In the ToDo-list I need 3 fields:
1: number =how many,
2: days /months /years
3: from today or from the original due-date,
for being able to say f.e. “add now 1 year to today” or “add now 14 days to the original due-date”.

Or even the best: If this calculation could be inside of the Pickaday-Popup, this would be really a dream :slight_smile: .

These two work for me, but they do not bring the full features needed for me:
$:/_Macros/FutureDate.js, file to download
and Date Conversion Macros .

How can I adjust them to get the features which I need?
Or do you know any other possibility?

.

Here you can play around with it: Tests >Meine ToDos

Thank you all, Noushka
TW 5.3.3, Firefox, Windows 10

Evans formula Plugin is still available and includes a lot of features including dates Formulas for TiddlyWiki — spreadsheet-inspired number crunching and @EricShulman’s timer tools has a lot see https://tiddlytools.com/ and search for time.

Thankyou Tones,
but I feel completely lost, have no idea how to add days to <<now>>.
In TiddlyWikiFormula I tried:

  • (= add_days((= <<now>> =),1) =)
  • (= add_days((= <<now YYYY0MM0DD>> =),1) =)
  • (= add_days(<<now>>,1) =)
  • (= add_days({{!!now}},1) =) (with field “now” and in that field <<now>>),
    all without success.

And in Playground >Conversion Macros I tried

  • <<date-from-field now 1>> with <<now>> in field “now” and also with <<now YYYY0MM0DD>>
  • <<date-from-field <<now>> 1>>
  • <<date-from-field {{!!now}} 1>>
  • and with a button to set field “timestamp”
    <$button class="timebutton"><$action-setfield timestamp=<<now "YYYY 0MM 0DD">>/>Set timestamp</$button> <$transclude field="timestamp"/> + in the tiddler 10 Days from now: <<date-from-field timestamp 10>>

also all without success.

Sorry, I have no idea, please help…

I would be happy to help but it’s night here and I am doing a bush walk tomorrow and will not be back for 12+ hours. There should be examples on Evans website and maybe someone else can help.

Dear Tones, don’t hurry or worry.

There should be examples on Evans website

I studied it, experimented,… but still… not successful :flushed:

So, I wait for someone’s else help or for you after your walk. Have a nice walk!!

I put together some filter operators around date math I’ve used for years. The main one is adddays but I also have one for months and years. Not sure if that’ll be useful to you. I don’t have my computer but found and old post I made that mentioned it.

Woha :slight_smile: , that works :slight_smile: YEAH, THANKS!!
I’ll do now some experiments, trying to solve additionally wishes, like being able to put number of dates to add in a field & to choose from “today” or “original due-date”.
I’ll try to solve that at first by my own. If I get stuck, I’ll come back.

Okay, I give up for now :roll_eyes:
So please @stobot, I need your help for:

I want to be able, to write different amounts for to add in view mode. My idea was with <$edit-text tiddler=<<currentTiddler>> field="add" size=1/> or with <$edit-text tiddler=<<otherTiddler>> field="add" size=1/>

and to build then a button with

<$button>
<$action-setfield due=<<dateadd days:{{otherTiddler!!add}}>> />
Add days >klick
</$button>

or with

<$button>
<$action-setfield due=<<dateadd days:{{currentTiddler!!add}}>> />
Add days >klick
</$button>

but these buttons only emptied the due-field…

And, ideally I would like the possibility not only to choose the number (of days), but instead also to write something like “add 2 years” or “add 1 months and 3 days”,…

Before I head off for my walk it is possibly to avoid date calculations for common periodical items. I have explained this before in talk.tiddlywiki.

  • This is arguably a superior method for a number of reasons.
  • One of the most is no need to restamp with a future date, just today.
  • This method makes items due N days after it was last done, but depending on the view you are looking through. Tag it with fortnightly to indicate fortnightly, monthly for monthly.

If you set a field for example fortnight-stamp, and you stamp it with now, you can use the days operator days[-14] to test if it is older than 14 days or not. This means it is due once 14 days have passed, and 15 days …, then on re-stamp is due in another 14 days.

  • In this model something stays due until stamped with today, as a result the very same task can be viewed from multiple periodical views at once, for example a list can show all due in the current fortnight and current 4 week period.

I have done a lot of work on periodicity, so happy to share.

1 Like

@TW_Tones , I do not really understand. Do you have examples somewhere to show /try them /experimenting with them for better understanding?

Hello @Noushka, I went back to the post I’d referenced and found that I did post updated code that was more direct, I suspect due to the same thing you were running up against - ease of using within filters. Mostly I just put versions together that only took one parameter, and put the other part (units of time) into the function itself, so rather than passing “days”, there’s a separate function for adddays(). Note there’s actually an adddays, addweeks, addmonths, addyears and then I added “the opposite” in daysuntil, monthsuntil, yearsuntil… so I could do countdowns. These functions assume you’re passing them a date in either standard format or just the first 8 digits.

So, going back to your example where you’re trying to pass transcluded parameters into the function, you can simplify by using a simple version.

Your pseudo code
<$action-setfield due=<<dateadd days:{{otherTiddler!!add}}>> />

Should work like
<$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">adddays{otherTiddler!!add}] }}}/>

datemath.js.json (6.8 KB)

Let me know if that works.

Hello @stobot ,
thanks, the second one works :slight_smile: !
In the Test-Wiki I build 2 tiddlers for that:

  • ThisTiddler” with your code inside buttons, Field “add” & field “due”.
  • And “otherTiddler” with the fields “add” & “due”.
  • (The first I couldn’t bring to work- it is the first button “add 1 Tag” in “otherTiddler”).

And then I build a button with an included edit-field of the amouint which should be added (“add”-field in “otherTiddler”). And it works :slight_smile: :

<$button>
<$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">adddays{otherTiddler!!add}] }}}/>
+ <$edit-text tiddler="otherTiddler" field="add" size=2/>Tage (von heute)
</$button>

But the next builded button does not work- the combination of

  • the button to make the calculation
  • plus edit-field of the amount
  • plus edit-field with the select-widget for choosing “adddays” /“addweeks”/… With this code it does not work:
<$button>
<$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">{otherTiddler!!whattoadd}{otherTiddler!!add}] }}}/>
+ <$edit-text tiddler="otherTiddler" field="add" size=2/> <$select tiddler='otherTiddler' field='whattoadd'>
<option>adddays</option>
<option>addweeks</option>
<option>addmonths</option>
<option>addyears</option>
</$select>
</$button>

I tried that part $value={{{ [<now "YYYY0MM0DD">{otherTiddler!!whattoadd}{otherTiddler!!add}] }}}/> also with 2 curly brackets like $value={{{ [<now "YYYY0MM0DD">{{otherTiddler!!whattoadd}}{otherTiddler!!add}] }}}/>

Is there a possibility to integrate that too?

(If there is a possibility for combining with the select-widget for choosing “adddays” /“addweeks”/…, then I would combine it at the end also with selecting <<now “YYYY0MM0DD”>> /original-due-date.

And at the final end I would really like to have this all inside the pickaday popup…

Hello @Noushka, even in your first example that works I’ve never seen someone put things like an edit-text inside the button before, kind of surprised that it worked.

To have a $select to select unit of time and an $edit-text and then have the button do the work, I believe the “proper” answer is to separate those components from each other. For the functions, since the new functions don’t take a parameter for the units, you’d need to do branching logic to use them - testing what value the user selected and then using the appropriate filter. I think using the old define syntax you could use something similar to what you put together, but the more proper way these days is to split it out. This also has the benefit of nice looking names inside your $select drop-down instead of the code names.

  1. Do the edit box outside of the button first
  2. Do the select outside the button either before or after the edit-box
  3. Do the branching logic. Buttons can contain the $action widgets, but it’s recommended to define them outside and then pass them into the button using the actions parameter.

So if I was building this using my code style, it’d be like this:

\procedure add-days() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">adddays{otherTiddler!!add}] }}}/>
\procedure add-weeks() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">addweeks{otherTiddler!!add}] }}}/>
\procedure add-months() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">addmonths{otherTiddler!!add}] }}}/>
\procedure add-years() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">addyears{otherTiddler!!add}] }}}/>

<$edit-text tiddler="otherTiddler" field="add" size="2"/>
<$select tiddler="otherTiddler" field="whattoadd">
<option>Days</option>
<option>Weeks</option>
<option>Months</option>
<option>Years</option>
</$select>
<$list filter="[{otherTiddler!!whattoadd}match[Days]]" variable="x"><$button actions=<<add-days>>>Add</$button></$list>
<$list filter="[{otherTiddler!!whattoadd}match[Weeks]]" variable="x"><$button actions=<<add-weeks>>>Add</$button></$list>
<$list filter="[{otherTiddler!!whattoadd}match[Months]]" variable="x"><$button actions=<<add-days>>>Add</$button></$list>
<$list filter="[{otherTiddler!!whattoadd}match[Years]]" variable="x"><$button actions=<<add-years>>>Add</$button></$list>

Which looks something like this with some selections made:
image

It works and is also fine :slight_smile:
But only in the test-wiki on tiddlyhost- not in my own :hot_face: .
In both wikis I have exactly the same tiddlers related to this date-calculation (otherTiddler & New Tiddler) - I imported them into my own wiki.

So there is anything else in my wiki what causes the issue. How to find that out???

Hmm not to my knowledge. I assume you already did a refresh due to it being JavaScript based? I can’t think of any other reason at the moment. Sorry.

Yes, I refreshed the wiki- but still, when I hit the button to add a day or similar, then it only empties the “due”-field…
:flushed: ?

The wiki is not a very old version that predates procedures is it? If so replacing the ‘procedure’ calls with ‘define’ calls might work?

Both wikis say, they are version 5.3.3, my private I just updated maybe 2 weeks ago.

Experimented… and found out 2 things:

  • Probably a mistake in your code- see below.
  • In my private wiki it calculates not nothing- instead it calculates only, when I choose “Days” and the calculation is correct. When choosing weeks, months or years, then it only empties the due-field.
  • Replaced ‘procedure’ with ‘define’ >did not change anything- not in the Test-Wiki and not in my private one.

I found a mistake in your \procedure add-days() <......-building ;-). (At least I think, it was a mistake).
But in the end the correction of this mistake does not solve the problem.

\procedure add-days() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">adddays{otherTiddler!!add}] }}}/>
\procedure add-weeks() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">addweeks{otherTiddler!!add}] }}}/>
\procedure add-months() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">addmonths{otherTiddler!!add}] }}}/>
\procedure add-years() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">addyears{otherTiddler!!add}] }}}/>

<$edit-text tiddler="otherTiddler" field="add" size="2"/>
<$select tiddler="otherTiddler" field="whattoadd">
<option>Days</option>
<option>Weeks</option>
<option>Months</option>
<option>Years</option>
</$select>
<$list filter="[{otherTiddler!!whattoadd}match[Days]]" variable="x"><$button actions=<<add-days>>>Add</$button></$list>
<$list filter="[{otherTiddler!!whattoadd}match[Weeks]]" variable="x"><$button actions=<<add-weeks>>>Add</$button></$list>
<$list filter="[{otherTiddler!!whattoadd}match[Months]]" variable="x"><$button actions=<<add-days>>>Add</$button></$list>
<$list filter="[{otherTiddler!!whattoadd}match[Years]]" variable="x"><$button actions=<<add-years>>>Add</$button></$list>

I corrected in <$list filter="[{otherTiddler!!whattoadd}match[Months]]" variable="x"><$button actions=<<add-days>>>Add</$button></$list> the <<add-days>> to <<add-months>>.
The result of this correction is in the Test-Wiki on tiddlyhost it calculates now the month correct (before it did not calculate at all). And in my own wiki now it empties the due-field, before it also did just nothing :joy:.

Now I tried the simpler code

<$button>
 <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">adddays[1]] }}}/>
add 1 days
</$button>

adddays works, doesn’t matter if field is empty before calculating or not. And it also works, when transcluding the “add”-field from another tiddler instead of [1].
The rest (weeks, months, years) only empties the due-field.

Interesting, well other than the typo where I didn’t change day to month on that one line, everything is working in the empty test wiki I have setup.

\procedure add-days() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">adddays{otherTiddler!!add}] }}}/>
\procedure add-weeks() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">addweeks{otherTiddler!!add}] }}}/>
\procedure add-months() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">addmonths{otherTiddler!!add}] }}}/>
\procedure add-years() <$action-setfield $field="due" $value={{{ [<now "YYYY0MM0DD">addyears{otherTiddler!!add}] }}}/>

<$edit-text tiddler="otherTiddler" field="add" size="2"/>
<$select tiddler="otherTiddler" field="whattoadd">
<option>Days</option>
<option>Weeks</option>
<option>Months</option>
<option>Years</option>
</$select>
<$list filter="[{otherTiddler!!whattoadd}match[Days]]" variable="x"><$button actions=<<add-days>>>Add</$button></$list>
<$list filter="[{otherTiddler!!whattoadd}match[Weeks]]" variable="x"><$button actions=<<add-weeks>>>Add</$button></$list>
<$list filter="[{otherTiddler!!whattoadd}match[Months]]" variable="x"><$button actions=<<add-months>>>Add</$button></$list>
<$list filter="[{otherTiddler!!whattoadd}match[Years]]" variable="x"><$button actions=<<add-years>>>Add</$button></$list>

----

{{!!due}}

Couple ideas you could test

  1. On the Advanced Filter, do the filters actually work? like [[20240523]adddays[1]],[[20240523]addmonths[1]], etc.? If yes, then it’s not the filter, it’s the implementation somewhere.
  2. The code doesn’t set the tiddler to add the due date to, so it’ll fall back to whatever the value of currentTiddler is when that line runs. You might want to do a check to see if the due field of an unexpected tiddler is being changed - either use AdvancedSearch to look for has[due] or even just notice what pops to the top of your “Recent” tab after running it.

Good luck!