Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cnl_core.mud.time.timeUpdate(time_string)
- local _,_,hh,mm,per = rex.find(time_string,"(\\d+):(\\d+) (am|pm)")
- if hh then
- mm = tonumber(mm)
- hh = tonumber(hh)
- if hh == 12 then hh = 0 end
- if per == "pm" then hh = hh + 12 end
- m.time_samples = m.time_samples or {}
- for i = 1,#m.time_samples-2 do table.remove(m.time_samples,1) end
- table.insert(m.time_samples, math.mod(getEpoch() - hh*60 - mm,1440))
- end
- end
- function cnl_core.mud.time.timeGet()
- if #m.time_samples == 0 then return nil end
- local sum,avg;
- for _,v in pairs(m.time_samples) do
- sum = (sum or 0) + v
- end
- avg = sum / #m.time_samples
- local ts = math.mod(getEpoch() - avg,1440)
- local hh = math.floor(ts/60)
- local mm = math.floor(ts-hh*60)
- return hh,mm
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement