BUG FIX! In my previous post, there were two errors in my code!
* in stop_timer(), when calculating the "start" and "stop" times, I was incorrectly treating seconds+milliseconds as if they were WHOLE SECONDS! * in showtable(), I was incorrectly treating the stored !!elapsed and !!total values as MILLISECONDS. I've fixed both problems, and posted the update tiddler here: http://TiddlyTools.com/timer.html Here's the new code with both bugs corrected: \define start_timer() <$button actions=""" <$vars time=<<now YYYY0MM0DD0hh0mm0ss0XXX>> > <$action-setfield startlist={{{ [{!!startlist}addsuffix[ ]addsuffix<time>trim[]] }}}/> <$action-setfield started=<<time>> stopped="" elapsed=""/> <$action-setfield button="stop"/> </$vars> """> start </$button> \end \define stop_timer() <$button actions=""" <$vars time=<<now YYYY0MM0DD0hh0mm0ss0XXX>> > <$action-setfield stoplist={{{ [{!!stoplist}addsuffix[ ]addsuffix<time>trim[]] }}}/> <$vars msec={{{ [{!!started}split[]last[3]join[]divide[1000]] }}} sec={{{ [{!!started}split[]butlast[3]last[2]join[]] }}} min={{{ [{!!started}split[]butlast[5]last[2]join[]multiply[60]] }}} hour={{{ [{!!started}split[]butlast[7]last[2]join[]multiply[3600]] }}} day={{{ [{!!started}split[]butlast[9]last[2]join[]multiply[86400]] }}}> <$vars start={{{ [<msec>add<sec>add<min>add<hour>add<day>] }}}> <$vars msec={{{ [<time>split[]last[3]join[]divide[1000]] }}} sec={{{ [<time>split[]butlast[3]last[2]join[]] }}} min={{{ [<time>split[]butlast[5]last[2]join[]multiply[60]] }}} hour={{{ [<time>split[]butlast[7]last[2]join[]multiply[3600]] }}} day={{{ [<time>split[]butlast[9]last[2]join[]multiply[86400]] }}}> <$vars stop={{{ [<msec>add<sec>add<min>add<hour>add<day>] }}}> <$action-setfield stopped=<<time>> elapsed={{{ [<stop>subtract<start>] }}}/> <$action-setfield total={{{ [{!!total}add{!!elapsed}] }}}/> <$action-setfield button="start"/> </$vars> </$vars> </$vars> </$vars> </$vars> """> stop </$button> \end \define reset_timer() <$button> reset <$action-deletefield startlist stoplist started stopped elapsed total button /> </$button> \end \define showtable() <$vars elapsed_min={{{ [{!!elapsed}divide[60]trunc[]] }}} elapsed_minsec={{{ [<elapsed_min>multiply[60]] }}} elapsed_sec={{{ [{!!elapsed}subtract<elapsed_minsec>multiply[1000]trunc[]divide[1000]] }}}> <$vars total_min={{{ [{!!total}divide[60]trunc[]] }}} total_minsec={{{ [<total_min>multiply[60]] }}} total_sec={{{ [{!!total}subtract<total_minsec>multiply[1000]trunc[]divide[1000]] }}}> | started:|<$view field="started" format="date" template="[UTC]MMM DD YYYY 0hh:0mm:0ss.0XXX" />| | stopped:|<$view field="stopped" format="date" template="[UTC]MMM DD YYYY 0hh:0mm:0ss.0XXX" />| | elapsed:|<<elapsed_min>> minutes <<elapsed_sec>> seconds| | total:|<<total_min>> minutes <<total_sec>> seconds| </$vars> </$vars> \end <$reveal default={{!!button}} type="nomatch" text="stop"> <<start_timer>> <<reset_timer>> </$reveal> <$reveal default={{!!button}} type="match" text="stop"> <<stop_timer>> <<reset_timer>> </$reveal> <<showtable>> Just goes to show that even good coders make simple mistakes... enjoy, -e Eric Shulman TiddlyTools.com: "Small Tools for Big Ideas!" (tm) InsideTiddlyWiki: http://TiddlyTools.com/InsideTW -- 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 tiddlywiki+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/e9dfa4b0-711d-469d-848c-cc29e433713bo%40googlegroups.com.