"Pie countdown timer" and small filters to calculate between hours:minutes:seconds (in three fields) to seconds and back

I could not find it in @EricShulman 's great “All about time” colection yet…
Did I miss it or did anyone else build something to do this…

And while I am at this: How can I calculate the count of full minutes to a fixed time?

Best wishes Jan

The recent addition of unix time and the ability to convert it back to a tiddlywiki timestamp lets you perform maths of times and days, as unix time is numerical, you just need to convert whatever you are adding or subtracting into an appropriate number, then you can add them. I have not yet done this to teach you but I am confident it can be done.

1 Like

Hi @TW_Tones for the first two tasks I would like to have a relative solution.
Is there a filter for the rest after a division?

Hi @JanJo,

There is the remainder operator.

Fred

There is a lot online about the use of a unix date to do date and time maths. Most of the operations you need are in TiddlyWiki now. It remains easier to add or subtract a “period” (eg; hours/days) from a date to find a new date. It is a little more involved if you want to get the period between two dates.

  • However to use the unix date effectivly you want to have encoded a number for each of minutes, hours, days etc… in unix time, and multiply these by the number of them you wish to use, before adding and subtracting operations.
    • Something like this will be needed for any date maths so I think we can put together a resource to assist, and with 5.3.0 we can make custom operators to make it even smoother.
  • These same “custom operators” could then be used to convert a unix time “period” you calculated into a human readable period eg “3 days 2 hours”.

In short this is a great area for collaboration and shared code to simplify date maths and display, I may not be abe to contribute more for a few days, but will.

3667 seconds are:

Hours: [[3667]divide[[3600]floor[0]]

Minutes: [[3667]remainder[3600]divide[60]floor[0]]

Seconds: [[3667]remainder[60]]
Best wishes Jan

This seems like a place where the new functions might actually be helpful

\function to-seconds(hours, minutes, seconds) [<hours>multiply[3600]] [<minutes>multiply[60]] [<seconds>] +[sum[]]

\function to-hours(seconds) [<seconds>divide[3600]floor[]] [<seconds>remainder[3600]divide[60]floor[]] [<seconds>remainder[60]] +[join[:]]

<<to-seconds 2 40 35>>

<<to-hours 9635>>

<$text text={{{ [function[to-seconds],[1],[15],[0]] }}} />

<$text text={{{ [function[to-hours],[4500]] }}} />
6 Likes

Here is the result of the work that triggered the question: A pie-timer that allows to set and visualize a countdown. As poined out by @TW_Tones below, it depends on @EricShulman 's timeout.js which I need so often, that I would like to have it in the core.

$ _plugins_JJ_classroom_widgets_PieTimer.json (5.9 KB)

Thanks to all helpers and cheers!strong text

2 Likes

@JanJo thanks for sharing. I notice it has a dependancy the action timeout widget but also it would be complete if we can also select 0 from the value drop down.