Count Up Timer?

Sean Cole sean at pidigital.co.uk
Tue Nov 2 11:56:41 EDT 2021


Tidy. Took 10 seconds:

--------------------------------------------------------------------------
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
---------------------------------------------------------------



More information about the use-livecode mailing list