Add methods to get real world time

This commit is contained in:
Kirigaya Kazuto 2018-03-10 02:16:49 +08:00
parent 028d215107
commit 08a704d58f

View File

@ -1,5 +1,30 @@
local component=require("component")
local serialization = require("serialization")
local filesystem=require("filesystem")
function getWorldTimestamp()
local name=os.tmpname()
local f=io.open(name,"w")
f:close()
local ts=filesystem.lastModified(name)
filesystem.remove(name)
return ts
end
function getWorldTimeInfo(gmt)
if(gmt==nil) then gmt=0 end
local x=getWorldTimestamp()+gmt*3600*1000
local t=os.date("*t",math.ceil(x/1000))
t.msec=x%1000
t.unix=math.ceil(x/1000)
t.stamp=x
return t
end
function getWorldDate(gmt)
local t=getWorldTimeInfo(gmt)
return t.year,t.month,t.day,t.hour,t.min,t.sec,t.msec
end
function serialize(value)
return serialization.serialize(value)