# Countdown timer and calculation

Hy,

My goal is to show a countdowntimer until a given time (checkpoints).
Checkpionts are a neverending loop of 5 hours but are “fixed” times.
The base times are UTC so the users timezone should be added/substracted aswell.

I defenitly suck in math

I already have a php function that calculates these times, maybe that helps (the -30 minutes part is not needed) :

#now in sec
now = time.time()
#cp in sec
cp = 56060
#get start of this cp
startcp = cp * math.floor(now / cp)
#the time until the next cp - 30 min
delay = startcp + cp - now - (60 * 30)

The current “cycle” of checkpoints based on today are:
Checkpoints for Cycle 2017.15
*) 2017-04-18 01:00 CEST

1. 2017-04-18 06:00 CEST
2. 2017-04-18 11:00 CEST
3. 2017-04-18 16:00 CEST
4. 2017-04-18 21:00 CEST
5. 2017-04-19 02:00 CEST
6. 2017-04-19 07:00 CEST
7. 2017-04-19 12:00 CEST
8. 2017-04-19 17:00 CEST
9. 2017-04-19 22:00 CEST
10. 2017-04-20 03:00 CEST
11. 2017-04-20 08:00 CEST
12. 2017-04-20 13:00 CEST
13. 2017-04-20 18:00 CEST
14. 2017-04-20 23:00 CEST
15. 2017-04-21 04:00 CEST
16. 2017-04-21 09:00 CEST
17. 2017-04-21 14:00 CEST
18. 2017-04-21 19:00 CEST
19. 2017-04-22 00:00 CEST
20. 2017-04-22 05:00 CEST
21. 2017-04-22 10:00 CEST
22. 2017-04-22 15:00 CEST
23. 2017-04-22 20:00 CEST
24. 2017-04-23 01:00 CEST
25. 2017-04-23 06:00 CEST
26. 2017-04-23 11:00 CEST
27. 2017-04-23 16:00 CEST
28. 2017-04-23 21:00 CEST
29. 2017-04-24 02:00 CEST
30. 2017-04-24 07:00 CEST
31. 2017-04-24 12:00 CEST
32. 2017-04-24 17:00 CEST
33. 2017-04-24 22:00 CEST
34. 2017-04-25 03:00 CEST
35. 2017-04-25 08:00 CEST
All times UTC+0200

goals in short:

• Calculate time until next checkpoint and show result as countdown timer (H:M:S) and/or as progressbar
• When counter reaches “0” it should restart counter until next checkpoint

Can this be done and if yes…how?

If the checkpoint will be fixed in time (selected by you on the creating face state) then yes.
Also, if you want to use time in UTC, just use tags #DUh#, #DUm# and #DUs#, instead of calculating it from users time zone.

I suggest this:
Create a function that gives back current time in hours, including current day, mount and year:

``````(#DUH#+((#DD#+(#Dyyyy#*(365+(1/3))))*24))
``````

If those checkpoints occur every 5 hours, then use this:

``````(((x/5)-floor(x/5))*5)
``````

Change x into that function before and it will be counting from 0 to 5 every 5 hours (add, or subtract few hours to make sure it matches your checkpoints).

Since those checkpoints accurate in full hours, then for minutes and seconds you can just use current minutes and seconds (just subtract them from 60)

Hy, thanks for thinking with me.

So if i understand correctly:

If you have 4 pencils and i have 7 apples, how many pancakes will fit on the roof?
purple, because aliens don’t wear hats!

Joking aside, i’m terible at math formulas so bare with me

The reason i need to calculate including timezone is because the users are worlwide or does this automagicly displays including the users timezone?

so the complete string would be;

((((#DUH#+((#DD#+(#Dyyyy#*(365+(1/3))))*24))/5)-floor(x/5))*5)

correct?

Full formula (without current user correction):

``````((((#DUH#+((#DD#+(#Dyyyy#*(365+(1/3))))*24))/5)-floor((#DUH#+((#DD#+(#Dyyyy#*(365+(1/3))))*24))/5))*5)
``````

To add correction you will need to calculate user’s timezone (there is no tag showing it):
#DH# - current user hour (0-23)
#DUH# - current UTC hour (0-23)
use (#DH#-#DUH#) to get current time zone.

There is a catch:
Cose to midnight of UTC time this will change from (eg.) +2 into -22.
To prevent that use condition like this:

``````\$(#DH#-#DUH#)>-12?(#DH#-#DUH#):(24+(#DH#-#DUH#))\$
``````

This will give you current user timezone (I think).

Thanks!

But now i think of it…the checkpoint is at the same point in time worldwide.
Since its a counter and not a “clock” i dont need to use timezones.

this doesent work, or i am doing something wrong.
I “just” need to put this in the text field right?

It displayes a series of numbers in editor and a “0” on the watch (lg watch R)

And what do you get when you use that function for a current time in hours from before?

pardon my noobnes but what do you mean?

This one.
What do you get, when you input this into text?

1.0000000009313226

i was expecting at leat a time format like 00:00 or something

And the number changes over time

How does it change?
If it changes only in like a 4 place after the coma, just use on it function “round(x)”

It changes only every round hour

in this sequence:

0
1.0000000009313226
1.9999999995343387
3.0000000004656613
3.9999999990686774

so its seems it calculates only at the whole hour
my guess is it takes the hour to calculate instead of every minute, or even better every second.
And them to reformat that to a hh:mm:ss

Since all your checkpoints are at full minutes that’s all you need.
Use this for the end text:
(round(x)):(60-#DUm#):(60-#DUs#)
And under that x, place that function that gives you 0; 1.0000000009313226; 1.9999999995343387…

Cool! That works…almost…

``````(round((#DUH#+((#DD#+(#Dyyyy#(365+(1/3))))24)))) (12-#DUh#):(60-#DUmZ#):(60-#DUsZ#)
``````

but it outputs “2017498 3:8:4” on my watcg (not in editor)

so i somehow have to “hide” that year/month thing and somehow the minutes and seconds dont have a leading zero.

But hey!..it does seem to calculate correctly! wich is great!

You used the function that shows the current time in hours (with year/month) instead of that full formula:

i now got this:

``````(round(((((#DUH#+((#DD#+(#Dyyyy#(365+(1/3))))24))/5)-floor((#DUH#+((#DD#+(#Dyyyy#(365+(1/3))))24))/5))*5)))(12-#DUh#):(59-#DUmZ#):(59-#DUsZ#)
``````

works! Only the minutes and seconds dont have a leading zero

Nop…i was to fast…didnt work…with the above code a “constant” of 2 is used.

Back to the drawingboard!