Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <alias name="luatest2" language="Lua" id="2948">
- <value><![CDATA[local timeDiff = function(t2,t1)
- local d1,d2,carry,diff = os.date('*t',t1),os.date('*t',t2),false,{}
- local colMax = {60,60,24,os.date('*t',os.time{year=d1.year,month=d1.month+1,day=0}).day,12}
- d2.hour = d2.hour - (d2.isdst and 1 or 0) + (d1.isdst and 1 or 0)
- for i,v in ipairs({'sec','min','hour','day','month','year'}) do
- diff[v] = d2[v] - d1[v] + (carry and -1 or 0)
- carry = diff[v] < 0
- if carry then diff[v] = diff[v] + colMax[i] end
- end
- return diff
- end
- local td=timeDiff(os.time(),os.time{year=2011,month=11,day=6,hour=10,min=10,sec=5})
- for i,v in pairs(td) do print(i,v) end]]></value>
- </alias>
Add Comment
Please, Sign In to add comment