On Sunday, June 21, 2020 at 5:08:10 AM UTC-7, si wrote:
>
> I use TiddlyWiki as a task manager, among other things, and I thought it
> would be cool to know how long I spent working on a completed task.
> Off the top of my head I imagine having a "start/stop" button that will
> alternately add a timestamp to the fields "start" and "stop". Then I could
> (hopefully) create a macro that calculates the total time spent on the task.
>
I just put this together:
\define startbutton()
<$button> start
<$action-setfield start=<<now YYYY0MM0DD0hh0mm0ss0XXX>>/>
<$action-setfield stop=""/>
<$action-setfield elapsed=""/>
</$button>
\end
\define stopbutton()
<$button> stop
<$action-setfield stop=<<now YYYY0MM0DD0hh0mm0ss0XXX>>/>
<$action-setfield elapsed={{{ [{!!stop}subtract{!!start}] }}}/>
</$button>
\end
\define showtable()
<$vars min={{{ [{!!elapsed}divide[60000]trunc[]] }}}>
<$vars minsec={{{ [<min>multiply[60]] }}}>
<$vars sec={{{
[{!!elapsed}divide[1000]subtract<minsec>multiply[1000]trunc[]divide[1000]]
}}}>
| started:|<$view field="start" format="date" template="[UTC]MMM DD YYYY
0hh:0mm:0ss.0XXX" />|
| stopped:| <$view field="stop" format="date" template="[UTC]MMM DD YYYY
0hh:0mm:0ss.0XXX" />|
| elapsed:|<<min>> minutes <<sec>> seconds|
</$vars>
</$vars>
</$vars>
\end
<$reveal default={{!!start}} type="match" text="">
<<startbutton>>
</$reveal>
<$reveal default={{!!start}} type="nomatch" text="">
<$reveal default={{!!stop}} type="match" text="">
<<stopbutton>>
</$reveal>
<$reveal default={{!!stop}} type="nomatch" text="">
<<startbutton>>
</$reveal>
</$reveal>
<<showtable>>
notes:
* startbutton() sets the "start" field using a complete zero-padded time
value including milliseconds. This is the same format used by the TWCore
for the "created" and "modified" fields.
* stopbutton() sets the "stop" field and calculates elapsed time (i.e, stop
- start)
* showtable() calculates the elapsed time as minutes and seconds and
displays the results as a nicely formatted table, where:
* minutes ("min") are truncated to the nearest integer
* then multiplied by 60 to get the number of seconds in those whole
minutes ("minsec")
* seconds ("sec") subtracts the whole minutes (as "minsec") and then
rounds to 3 decimal places (i.e., milliseconds) by multiplying by 1000,
truncating, and dividing by 1000
* The first $reveal shows the startbutton if no start value is stored
* The second $reveal shows the stopbutton if a start value is stored but no
stop value is stored
* The third $reveal shows the startbutton again if both start and stop
values are stored
To use it:
* place the above code into a tiddler named "Timer"
* then, in any tiddler, simply write:
{{||Timer}}
Give it a try and let me know how it goes...
enjoy,
-e
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/7a8af7e0-595c-4dce-b3a7-40660ec20e42o%40googlegroups.com.