[TW5] Macro for saving timestamp in field – problem

381 views
Skip to first unread message

Thomas Elmiger

unread,
Aug 18, 2016, 4:07:46 AM8/18/16
to TiddlyWiki
Hi folks!

While still learning TW in small steps, I am "developping" my own todo list … and ran into a problem: When a task is done, I want to write the done-date in it’s own field.

Within the list of tasks I tried:

<$set name="donedate" value=<<teTimestampNow>> >
<$macrocall $name="todoBtnDone" remove="ToDoNow" date=<
<donedate>>/>
</$set>

with these macros:

\define todoBtnDone(remove, date)
<$fieldmangler>
<$button tooltip="This is done" class="todo-btn-invisible" message="tm-remove-tag" param="$remove$">
<$action-sendmessage $message="tm-add-tag" $param="ToDoDone"/>
<$action-setfield $field="todo-done" $value="$date$"/>
{{$:/core/images/full-screen-button}}
</$button>
</
$fieldmangler>
\end


\define teTimestampNow()
<$set name="timestamp" value=<<now YYYY0MM0DD0hh0mm0ss>> >
<<timestamp>>000
</$set>
\end

Problem: I can see the button (the button works actually and adds/removes tags as expected), BUT the output contains this as text output:

<$action-setfield $field="todo-done" $value="
20160818095228
000
"/>

... so it is not executed.

I am sure I did something wrong with the variable values <<donedate>> and or $date$ – but I can’t see it at the moment. Maybe you can? Or is there a better way to get a timestamp in the same format as standard modified and created? Do I hav to use JS and $tw.utils.stringifyDate(now)); for this?

Kind regards, Thomas

PMario

unread,
Aug 18, 2016, 4:54:03 AM8/18/16
to tiddl...@googlegroups.com
Hi Thomas,

Your <<now YYYY0MM0DD0hh0mm0ss>> is fine. TW will handle it. You don't need to add the 000. miliseconds. It will make your code easier too.

<$button>
<$action-setfield $field="todo-done" $value=<<now YYYY0MM0DD0hh0mm0ss>> /> click
</$button>

-m

PMario

unread,
Aug 18, 2016, 4:57:31 AM8/18/16
to TiddlyWiki
try this:

<$button>
<$action-setfield $field="todo-done" $value=<<now YYYY0MM0DD0hh0mm0ss000>> /> click
</$button>

-m

Thomas Elmiger

unread,
Aug 18, 2016, 7:11:08 AM8/18/16
to tiddl...@googlegroups.com
Thank you very much, Mario!

For your first answer (good to know!) and for the second, which solved my problem immediately.

Now I am having fun ;–)

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/rBFMyGenP5k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+unsubscribe@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/2c8136ac-eb65-4757-b5f6-16c8efd77fa1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

PMario

unread,
Aug 18, 2016, 2:35:58 PM8/18/16
to TiddlyWiki
On Thursday, August 18, 2016 at 1:11:08 PM UTC+2, Thomas Elmiger wrote:
Now I am having fun ;–)

Great! :)

Matabele

unread,
Aug 18, 2016, 8:10:01 PM8/18/16
to tiddl...@googlegroups.com
Hi

The tags may be modified using the ActionListops widget -- the entire code is then simply:

<$button tooltip="This is done" class="todo-btn-invisible">
<$action-listops $tags="ToDoDone -ToDoNow"/>
<$action-setfield $field="todo-done" $value=<
<now YYYY0MM0DD0hh0mm0ss>>/>
{{$:/core/images/full-screen-button}}
</$button>

regards

Thomas Elmiger

unread,
Aug 19, 2016, 3:00:16 AM8/19/16
to TiddlyWiki
Hi Matabele

Thank you for the input, when I took a look at the ActionListops widget, I did not realise the possibility to add and remove tags at the same time. This makes my code much simpler indeed!

I did not copy your exact solution as the action-setfield still would need the FieldMangler (ActionListops doesn’t). At the moment my macro looks like this:
\define todoBtnDone(remove,class:"")
<$set name="btnclass" value="todo-btn-invisible $class$">
<$button class=<<btnclass>> tooltip="This is done">
<$action-listops $tags="ToDoDone -$remove$"/>
<$action-listops $field="todo-done" $subfilter=<<now YYYY0MM0DD0hh0mm0ss>>/>
{{$:/
core/images/full-screen-button}}
</$button>
</
$set>
\end

Important: This appends done-dates instead of deleting former values … I am not sure yet, if this is useful, so I leave it like that. To go back to only one date I would clear the field like this:
<$action-listops $field="todo-done" $filter="[[]]"/>

Thanks again and have a nice day!
Thomas


Matabele

unread,
Aug 19, 2016, 5:16:44 AM8/19/16
to TiddlyWiki
Hi Thomas

No need to use an extra line to clear the field -- use the $filter= parameter directly -- this will overwrite the contents of the field.

<$action-listops $field="todo-done" $filter=<<now YYYY0MM0DD0hh0mm0ss>>/>

This could be used to update a timestamp with each click, for example.

regards

Thomas Elmiger

unread,
Aug 19, 2016, 11:28:23 AM8/19/16
to TiddlyWiki
Very cool, thank you Matabele!
Have a nice weekend,
Thomas

Matabele

unread,
Aug 19, 2016, 11:58:19 AM8/19/16
to TiddlyWiki
Hi Thomas

If you want to waste more time -- have a look at the cycled tags in the last example at the bottom of the 'keep Operator examples' on the ActionListops wiki.

This makes use of the cycle[] and keep[] filter operators which aren't yet in the core -- you will need to copy over the extended listops filters ($:/core/modules/filters/x-listops.js) from the wiki for these to work in your wiki.

regards
Reply all
Reply to author
Forward
0 new messages