Page 1 of 1
convert time/date
Posted: Saturday 23 November 2024 20:21
by manjh
I want to use the lastupdate value to check if devices are updated for a set period.
What I get back from lastupdate is (for instance):
Is there a simple way (in LUA) to convert this into a a value that I can store, and compare in future values?
Re: convert time/date
Posted: Sunday 24 November 2024 13:07
by FlyingDomotic
If you're using "classical" LUA, then time elapsed since device's last update in seconds could be computed with:
Code: Select all
function lastSeen(device)
timestamp = otherdevices_lastupdate[device] or device
y, m, d, H, M, S = timestamp:match("(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)")
difference = os.difftime(os.time(), os.time{year=y, month=m, day=d, hour=H, min=M, sec=S})
return difference
end
Called by "seconds = lastSeen("My device")" will load number of seconds since "My device" last update.
Re: convert time/date
Posted: Monday 25 November 2024 17:58
by manjh
thanks for your help!