Bolodefchoco_LUAXML

[Function] getTime

Jul 3rd, 2016
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 03/07/2016
  3. --Last update: 23/01/2017
  4. --[[ Notes:
  5.     Does:
  6.         Retorna time em anos, meses, semanas, dias, horas, minutos e segundos.
  7.     Args:
  8.         time --> Tempo total em segundos a ser transformado
  9. ]]--
  10.  
  11. getTime = function(time)
  12.     if type(time) ~= "number" then return "?" end
  13.  
  14.     local info = {}
  15.     local n = {}
  16.  
  17.     local h = 60 * 60
  18.     local d = h * 24
  19.     local we = d * 7
  20.     local mo = d * 30.41666
  21.     local y = d * 365
  22.  
  23.     n[1] = {"years",time / y}
  24.     n[2] = {"months",(time % y) / mo}
  25.     n[3] = {"weeks",((time % y) % mo) / we}
  26.     n[4] = {"days",(((time % y) % mo) % we) / d}
  27.     n[5] = {"hours",((((time % y) % mo) % we) % d) / h}
  28.     n[6] = {"minutes",time / 60 % 60}
  29.     n[7] = {"seconds",time % 60}
  30.  
  31.     for i,v in next,n do
  32.         v[2] = math.floor(v[2])
  33.         if v[2] > 0 then
  34.             info[math.min(#info + 1,i)] = v[2] .. " " .. v[1]:sub(1,-(v[2] == 1 and 2 or 1))
  35.         end
  36.     end
  37.  
  38.     return table.concat(info,", ")
  39. end
Advertisement
Add Comment
Please, Sign In to add comment