Countdown

Forums Desktop Info Countdown

Viewing 5 reply threads
  • Author
    Posts
    • #1934
      AvatarJeff

      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
    • #1936
      GlennGlenn
      Keymaster

      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
    • #1943
      AvatarJ
      Participant

      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
      • #1944
        GlennGlenn
        Keymaster

        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 604800-uptime or 6 days, 23 hours would be 601200-uptime. Divide that by 86400 would give you the number of days remaining:

        (601200-uptime)/86400

        That would give you a countdown in fraction of days, eg 6.5 days or 2.34 days etc.

        0
    • #1946
      AvatarJ
      Participant

      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 12 months ago by AvatarJ.
      0
    • #1948
      AvatarJ
      Participant

      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 12 months ago by AvatarJ.
      • This reply was modified 12 months ago by AvatarJ.
      1+
      • #1951
        GlennGlenn
        Keymaster

        OMG does that work!?! I am impressed! 🙂

        0
        • #1952
          AvatarJ
          Participant

          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
          • #1958
            GlennGlenn
            Keymaster

            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
    • #2038
      GlennGlenn
      Keymaster

      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
Viewing 5 reply threads
  • The topic ‘Countdown’ is closed to new replies.
Do NOT follow this link or you will be banned from the site!