Countdown
› Forums › Desktop Info › Countdown
 This topic has 9 replies, 3 voices, and was last updated 10 months, 1 week ago by Glenn.

AuthorPosts


Jeff
I would like to do a countdown between boot time and an arbitrary time in the future (for example, the next 3am after 6 days, 23hr and 30 minutes have passed.)
Is it possible to do date math directly?
thanks
0 
GlennKeymaster
Hi Jeff, DTI doesn’t do date math. Some kind of date math might be feasible but your particular example seems like a real edge case.
0 
JParticipant
The idea is to give users a countdown until their next forced reboot. Not so much an edge case as an innovative tool for something very common. 😉
In my organization it’s 7 days after your last reboot (lets users better control the timing of their updates while still being consistent). Specifically, 3am, after at least 6days, 23hours have passed.
Even just counting 7 days exactly would be fine if it was simple.
Thanks
0
GlennKeymaster
ok. If we had access to the absolute seconds in the UPTIME item we could do a simple calculation to find the difference between 7 days and the uptime, which is 604800uptime or 6 days, 23 hours would be 601200uptime. Divide that by 86400 would give you the number of days remaining:
(601200uptime)/86400
That would give you a countdown in fraction of days, eg 6.5 days or 2.34 days etc.
0


JParticipant
You jogged my mentalbraining –
This gets the offset between 3am and the hour of the day the machine rebooted… then subtracts 2 minutes and saves it in seconds as %bootsec%
BOOTTIME=active:2,{{((((3%5)*3600)+((60%6)*60))120}},set:bootsec,hidden:1
THEN, this determines how long it will be until 3am, 7days from now, minus 2 minutes ( I’ll probably extend that to minus 30min to account for patching).
UPTIME=active:2,interval:60,display:{{Round(((7*(86400+%bootsec%))((%1*86400)+(%2*3600)+(%3*60)))/(24 * 3600))}} Days {{Round(FRAC(((7*86400+%bootsec%)((%1*86400)+(%2*3600)+(%3*60)))/(24 * 3600))*24)}} Hours {{Round(FRAC(FRAC(((7*86400+%bootsec%)((%1*86400)+(%2*3600)+(%3*60)))/(24 * 3600))*24)*60)}} Minutes
I’m sure I could do it with less code or make it pretty in a function, but it works.
Thanks for the spark.
 This reply was modified 10 months, 3 weeks ago by J.
0 
JParticipant
Oops… couple mistakes fixed here. This works.
BOOTTIME=active:2,set:bootsec,display:{{((((2%5)*3600)+((60%6)*60))240)}},hidden:1
UPTIME=active:2,interval:60,display:{{Round((((7*86400)3600+(%bootsec%))((%1*86400)+(%2*3600)+(%3*60)))/(24*3600))}} Days {{Round(FRAC((((7*86400)3600+(%bootsec%))((%1*86400)+(%2*3600)+(%3*60)))/(24*3600))*24)}} Hours {{Round(FRAC(FRAC((((7*86400)3600+(%bootsec%))((%1*86400)+(%2*3600)+(%3*60)))/(24 * 3600))*24)*60)}} Minutes
 This reply was modified 10 months, 3 weeks ago by J.
 This reply was modified 10 months, 3 weeks ago by J.
1+
GlennKeymaster
OMG does that work!?! I am impressed! 🙂
0
JParticipant
In principle, but I’m seeing it’s not quite perfect yet. I need to break it down and simplify. I’ll post the final.
0
GlennKeymaster
I haven’t been able to work out the “next 3am after 7 days since the last boot” thing. I would have thought that you would want it to boot at exactly the same time exactly every 7 days. For example, if a machine was off for two days, do you want it to boot 7 days after it starts again or 7 days after the last boot or exactly 3am every Sunday?
0



GlennKeymaster
Using the new tools in v1.18 I’ve been able to more or less get what you’re after:
# current date/time in seconds datetime=active:1,interval:1,display:%8,set:datetime,hidden:1 # last boot time in seconds boottime=active:1,interval:1,display:%8,set:boottime,hidden:1 # get time of day of last boot boottime=active:1,interval:1,display:%5,set:boothours,hidden:1 boottime=active:1,interval:1,display:%6,set:bootmins,hidden:1 boottime=active:1,interval:1,display:%7,set:bootsecs,hidden:1 # wind back to midnight of day of last boot set=key:midnight,value:{{%boottime%%boothours%*3600%bootmins%*60%bootsecs%}} # add 7 days and 3 hours to 3am set=key:reboottime,value:{{%midnight%+86400*7+3600*3}} # countdown is difference with now set=key:countdown,value:{{%reboottime%%datetime%}} # display countdown in days hours minutes seconds text=active:1,interval:1,text:Countdown,display:{{trunc(%countdown%/86400)}} days {{trunc(mod(%countdown%\,86400)/3600)}} hrs {{trunc(mod(mod(%countdown%\,86400)\,3600)/60)}} mins {{mod(mod(mod(%countdown%\,86400)\,3600)\,60)}} secs
This counts down to 3am, 7 days after the last boot. What it doesn’t account for is when the last boot is greater than 7 days ago. That will give a negative countdown.
0


AuthorPosts