Page 1 of 1

LUA TimeDiff not working?!

Posted: Thursday 04 May 2017 16:30
by emme
got a wired thing....

Code: Select all

function timeDiff(dName,dType)
    if dType == 'v' then 
        updTime = uservariables_lastupdate[dName]
    elseif dType == 'd' then
        updTime = otherdevices_lastupdate[dName]
    end 
    t1 = os.time()
    year = string.sub(updTime, 1, 4)
    month = string.sub(updTime, 6, 7)
    days = string.sub(updTime, 9, 10)
    hour = string.sub(updTime, 12, 13)
    minutes = string.sub(updTime, 15, 16)
    seconds = string.sub(updTime, 18, 19)

    t2 = os.time{year=year, month=month, day=days, hour=hour, min=minutes, sec=seconds}
    tDiff = os.difftime(t1,t2)
    return tDiff
end
the

Code: Select all

t2 = os.time{year=year, month=month, day=days, hour=hour, min=minutes, sec=seconds}
rturns this error:
field 'day' missing in date table

Re: LUA TimeDiff not working?!

Posted: Friday 05 May 2017 15:54
by SweetPants

Re: LUA TimeDiff not working?!

Posted: Tuesday 13 June 2017 12:26
by zicht
I use this :

Code: Select all

function timedifference (s)   --- tijdverschil bepalen sinds laatste schakeling in sec
   if s == nil then print("Error  ") end
   year = string.sub(s, 1, 4)
   month = string.sub(s, 6, 7)
   day = string.sub(s, 9, 10)
   hour = string.sub(s, 12, 13)
   minutes = string.sub(s, 15, 16)
   seconds = string.sub(s, 18, 19)
   t1 = os.time()
   t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
   difference = os.difftime (t1, t2)
   return difference
end
Call it like

Code: Select all

difference2 = timedifference(otherdevices_lastupdate['Beweging Woonkamer'])
never have any problem.
I only see dayfield missing when i use

Code: Select all

difference2 = timedifference(Devicechanged_lastupdate['Beweging Woonkamer'])
But there is no reason to use devicechanged as otherdevices will return the exact wanted result