Rs2Soft: Eximius - DC++

Please login or register.

Login with username, password and session length
Advanced search  

News:

Eximius help hub at  rs2soft@no-ip.com:2500 and  supporthub.rs2soft.nl:2500

Author Topic: Convert Time  (Read 439 times)

0 Members and 1 Guest are viewing this topic.

Mutor

  • RS2Soft Scripter
  • Full Member
  • ****
  • Gender: Male
  • Posts: 130
  • Eximius
    • WWW
Convert Time
« on: July 21, 2009, 02:44:17 AM »
Code: [Select]
-- Converts an os.time() value to it's past or future value, returns a formatted string. By Mutor
Convert = function(time)
if time then
local s,x,n = "",0,os.time()
local tab = {{31556926,"year"},{2592000,"month"},{604800,"week"},
{86400,"day"},{3600,"hour"},{60,"minute"},{1,"second"}}
if time > 0 then
if time < 2145876659 then
if n > time then
time = n - time
elseif n < time then
time = time - n
end
for i,v in ipairs(tab) do
if time > v[1] then
x = math.floor(time/v[1])
if x > 1 then v[2] = v[2].."s" end
if x > 0 then
s = s..x.." "..v[2]..", "
time = time-x*v[1]
end
end
end
collectgarbage("collect")
return s:sub(1,-3)
else
return "Invalid date or time supplied. [must be pre "..os.date("%m/%d/%Y",2145876659).."]"
end
else
return "Invalid date or time supplied. [must be post "..os.date("%m/%d/%Y",86400).."]"
end
else
return "Invalid date or time supplied."
end
end
Logged
Respectfully,

Mutor

[ Mutor's Eximius ]
Pages: [1]
« previous next »