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
2017-04-18 06:00 CEST
2017-04-18 11:00 CEST
2017-04-18 16:00 CEST
2017-04-18 21:00 CEST
2017-04-19 02:00 CEST
2017-04-19 07:00 CEST
2017-04-19 12:00 CEST
2017-04-19 17:00 CEST
2017-04-19 22:00 CEST
2017-04-20 03:00 CEST
2017-04-20 08:00 CEST
2017-04-20 13:00 CEST
2017-04-20 18:00 CEST
2017-04-20 23:00 CEST
2017-04-21 04:00 CEST
2017-04-21 09:00 CEST
2017-04-21 14:00 CEST
2017-04-21 19:00 CEST
2017-04-22 00:00 CEST
2017-04-22 05:00 CEST
2017-04-22 10:00 CEST
2017-04-22 15:00 CEST
2017-04-22 20:00 CEST
2017-04-23 01:00 CEST
2017-04-23 06:00 CEST
2017-04-23 11:00 CEST
2017-04-23 16:00 CEST
2017-04-23 21:00 CEST
2017-04-24 02:00 CEST
2017-04-24 07:00 CEST
2017-04-24 12:00 CEST
2017-04-24 17:00 CEST
2017-04-24 22:00 CEST
2017-04-25 03:00 CEST
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
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)
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).
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…