[cmd] ElapsedTime

stable
By Strooth in Miscellaneous Published December 2021 👁 1,119 views 💬 0 comments

Description

Gets the time of start to the time of finish of backtest for custom report on length. Usage CC_ElapsedTime(Time())
HaasScript
-- Author: Strooth - Findme on discord - strooth#4739
-- Feel free to donate to support my work or if my script helped you in any way <3
-- BTC Adress: 33MsEAbA8tg7SpohgnCpSrmPTBih2UkhxQ

DefineCommand('ElapsedTime', 'Elapsed Time from Start to Finish')
local time = DefineParameter(NumberType, 'time', 'start timestamp', false, -1, "Time(), CreateTimestamp()")
local report = DefineParameter(BooleanType, 'report', 'show the custom report as well', false, false, "stringtype")
if time == -1 and Load('ElapsedTimeTimer', -1) == -1 then 
    Save('ElapsedTimeTimer', Time())
end
local timediff = function(t)
          local getdiff = function(t)
          local d = Time()-IfNull(t, Time())
          local w = Floor((CurrentDate(d)-1)/7)
          return {
            years = CurrentYear(d)-1970, 
            months = CurrentMonth(d)-1, 
            weeks = w, 
            days = Sub(CurrentDate(d)-1, w*7), 
            hours = CurrentHour(d), 
            mins = CurrentMinute(d)}
          end 
          local out 
          for key, value in pairs(getdiff(t)) do
            if NotEquals(IfNull(value, 0), 0) then 
            out = StringJoin(IfNull(out, ' '), value..' '..key, ' ')
           end 
          end
          return IfNull(out, 'None')
  end 
time = timediff(Load('ElapsedTimeTimer', time))
if report == true and Finalize() then 
  CustomReport('Elapsed Time', time)
end 
DefineOutput(StringType, time, "the formatted string of time elapsed", 'string')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!