Count Up Timer?

Tom Glod tom at makeshyft.com
Mon Nov 1 18:28:29 EDT 2021


Hey Dan, I'm pretty sure this handler works.  But it only does Days,
Hours,Minutes and Seconds.
I'm sure you can add to it. (human readable section)

Cheers,

Tom

--------------------------------------------------------------------------

*function* TimeDisplay HowMany,DisplayHow

*if* DisplayHow = "Duration" *then*

*//**************************************************************

*if* AppStarterStackSettings["default"]["Time Unit"] = "seconds" *then*

*return* round(HowMany / 1000,3) & "s"

*else* *if* AppStarterStackSettings["default"]["Time Unit"] = "milliseconds"
*then*

*return* HowMany & "ms"

*else* *if* AppStarterStackSettings["default"]["Time Unit"] = "microseconds"
*then*

*end* *if*

*else* *if* DisplayHow = "Human Readable" *then*

*//**************************************************************

*local* final_output = "<d> days <hh>:<mm>:<ss>"

*local* running_second_count

*local* next_calculation

*set* itemdelimiter to "." *-- we are looking at boths sides of the decimal
place*

*put* round(HowMany / 1000) into HowMany *-- convert to seconds*

*// 86,400 seconds in an day*

*// 3600 in an hour*

*// 60 seonds in a minute*

*// replace counts as you go*

*-- days*

*put* HowMany / 86400 into next_calculation

*if* next_calculation < 1 *then*

*put* HowMany into running_second_count

*replace* "<d>" with "0" in final_output

*else*

*// how many days?*

*replace* "<d>" with item 1 of next_calculation in final_output

*put* (HowMany) - (item 1 of next_calculation * 86400) into
running_second_count

*end* *if*

*-- hours*

*put* running_second_count / 3600 into next_calculation

*if* next_calculation < 1 *then*

*replace* "<hh>" with "00" in final_output

*else*

*// how many hours?*

*if* the number of characters in item 1 of next_calculation = 1 *then*

*replace* "<hh>" with "0" & item 1 of next_calculation in final_output

*else*

*replace* "<hh>" with item 1 of next_calculation in final_output

*end* *if*

*put* (running_second_count) - (item 1 of next_calculation * 3600) into
running_second_count

*end* *if*

*-- minutes*

*put* running_second_count / 60 into next_calculation

*if* next_calculation < 1 *then*

*replace* "<mm>" with "00" in final_output

*else*

*// how many minutes?*

*if* the number of characters in item 1 of next_calculation = 1 *then*

*replace* "<mm>" with "0" & item 1 of next_calculation in final_output

*else*

*replace* "<mm>" with item 1 of next_calculation in final_output

*end* *if*

*put* (running_second_count) - (item 1 of next_calculation * 60) into
running_second_count

*end* *if*

*-- seconds*

*put* running_second_count into next_calculation

*if* next_calculation < 1 *then*

*replace* "<ss>" with "00" in final_output

*else*

*// how many minutes?*

*if* the number of characters in item 1 of next_calculation = 1 *then*

*replace* "<ss>" with "0" & next_calculation in final_output

*else*

*replace* "<ss>" with next_calculation in final_output

*end* *if*

*end* *if*

*end* *if*

*//**************************************************************

*return* final_output

*end* TimeDisplay

---------------------------------------------------------------

On Mon, Nov 1, 2021 at 5:47 PM Dan Friedman via use-livecode <
use-livecode at lists.runrev.com> wrote:

> Anyone ever done a count up timer?   For example, if we supply the seconds
> of 1605553200, we want to display the number of years, months, days, hours,
> minutes and seconds since that time.   For example, "How long have you been
> alive?".   This needs to be precise – need to account for leap years, days
> in month, etc.
>
> Save me!!   :)
>
> -Dan
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


-- 
Tom Glod
Founder & Developer
MakeShyft R.D.A (www.makeshyft.com)
Mobile:647.562.9411



More information about the use-livecode mailing list