Advertisement
cnl_cnl_cnl

Untitled

Mar 6th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. function cnl_core.mud.time.timeUpdate(time_string)
  2. local _,_,hh,mm,per = rex.find(time_string,"(\\d+):(\\d+) (am|pm)")
  3. if hh then
  4. mm = tonumber(mm)
  5. hh = tonumber(hh)
  6.  
  7. if hh == 12 then hh = 0 end
  8. if per == "pm" then hh = hh + 12 end
  9. m.time_samples = m.time_samples or {}
  10. for i = 1,#m.time_samples-2 do table.remove(m.time_samples,1) end
  11. table.insert(m.time_samples, math.mod(getEpoch() - hh*60 - mm,1440))
  12. end
  13. end
  14.  
  15. function cnl_core.mud.time.timeGet()
  16. if #m.time_samples == 0 then return nil end
  17. local sum,avg;
  18. for _,v in pairs(m.time_samples) do
  19. sum = (sum or 0) + v
  20. end
  21. avg = sum / #m.time_samples
  22. local ts = math.mod(getEpoch() - avg,1440)
  23. local hh = math.floor(ts/60)
  24. local mm = math.floor(ts-hh*60)
  25. return hh,mm
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement