local N=string.lower local x,o,w,V,K,p="\109\105\110\117\116\101","\104\111\117\114","\100\097\121","\109\111\110\116\104","\121\101\097\114","\109\097\120"local m,E=2592000,30672000 local r,B,l,U="\100\101\102\097\117\108\116","\099\111\108\111\110","\115\104\111\114\116","\102\117\108\108"local Q={second=" \115\101\099 ",minute=" \109\105\110 ",hour=" \104\114 ",day=" \100 ";month=" \109\111\110 ",year=" \121\114 "}local T={second="\115\101\099 ";minute="\109\105\110\115 ",hour="\104\114\115 ";day="\100 ";month="\109\111\110 ";year="\121\114\115 "}local s={second=" \115\101\099\111\110\100 ";minute=" \109\105\110\117\116\101 ",hour=" \104\111\117\114 ";day=" \100\097\121 ";month=" \109\111\110\116\104 ",year=" \121\101\097\114 "}local u={second=" \115\101\099\111\110\100\115 ";minute=" \109\105\110\117\116\101\115 ",hour=" \104\111\117\114\115 ";day=" \100\097\121\115 ";month=" \109\111\110\116\104\115 ";year=" \121\101\097\114\115 "}local function i(N,x)return(N-N%x)/x end local function W(x,o,w)local V if o~=nil then V=N(o)else V=nil end if V==r or V==B or V==nil then local N,o,V,K=0,0,0,0 if x>=3600 then N=x%3600 o=N%60 V=i(x,3600)K=i(N,60)elseif x<3600 and x>=60 then o=x%60 K=i(x,60)else o=x K=0 end if V<10 and w==true then V="\048"..V end if K<10 and x>=3600 or K<10 and(x<3600 and w==true)then K="\048"..K end if o<10 and x>=60 then o="\048"..o end if x<60 then return x elseif x<3600 and x>=60 then return K..("\058"..o)elseif x>=3600 then return V..("\058"..(K..("\058"..o)))end elseif V~=r or V~=nil or V~=B then if w==true then warn("\084\070\077\058 \090\101\114\111\115 \097\114\101 \111\110\108\121 \116\111\103\103\108\097\098\108\101 \102\111\114 \116\104\101 \100\101\102\097\117\108\116 \102\111\114\109\033")end local N,o,K,p,r,B,W,M,j,D,d=0,0,0,0,0,0,0,0,0,0,0 local Z,O,g,I,y,q if x<60 then if V==l then if x>1 then O=T.second else O=Q.second end elseif V==U then if x>1 then O=u.second else O=s.second end end return x..O elseif x<3600 then B=x%60 d=i(x,60)if V==l then if d>1 then Z=T.minute else Z=Q.minute end if B>1 then O=T.second else O=Q.second end elseif V==U then if d>1 then Z=u.minute else Z=s.minute end if B>1 then O=u.second else O=s.second end end return d..(Z..(B..O))elseif x<86400 and x>=3600 then r=x%3600 B=r%60 D=i(x,3600)d=i(r,60)if V==l then if D>1 then g=T.hour else g=Q.hour end if d>1 then Z=T.minute else Z=Q.minute end if B>1 then O=T.second else O=Q.second end elseif V==U then if D>1 then g=u.hour else g=s.hour end if d>1 then Z=u.minute else Z=s.minute end if B>1 then O=u.second else O=s.second end end return D..(g..(d..(Z..(B..O))))elseif x<m and x>=86400 then p=x%86400 r=p%3600 B=r%60 j=i(x,86400)D=i(p,3600)d=i(r,60)if V==l then if j>1 or j==0 then I=T.day else I=Q.day end if D>1 or D==0 then g=T.hour else g=Q.hour end if d>1 or d==0 then Z=T.minute else Z=Q.minute end if B>1 or B==0 then O=T.second else O=Q.second end elseif V==U then if j>1 or j==0 then I=u.day else I=s.day end if D>1 or D==0 then g=u.hour else g=s.hour end if d>1 or d==0 then Z=u.minute else Z=s.minute end if B>1 or B==0 then O=u.second else O=s.second end end return j..(I..(D..(g..(d..(Z..(B..O))))))elseif x<E and x>=m then K=x%m p=K%86400 r=p%3600 B=r%60 M=i(x,m)j=i(K,86400)D=i(p,3600)d=i(r,60)if V==l then if M>1 or M==0 then y=T.month else y=Q.month end if j>1 or j==0 then I=T.day else I=Q.day end if D>1 or D==0 then g=T.hour else g=Q.hour end if d>1 or d==0 then Z=T.minute else Z=Q.minute end if B>1 or B==0 then O=T.second else O=Q.second end elseif V==U then if M>1 or M==0 then y=u.month else y=s.month end if j>1 or j==0 then I=u.day else I=s.day end if D>1 or D==0 then g=u.hour else g=s.hour end if d>1 or d==0 then Z=u.minute else Z=s.minute end if B>1 or B==0 then O=u.second else O=s.second end end return M..(y..(j..(I..(D..(g..(d..(Z..(B..O))))))))elseif x>=E then o=x%E K=o%m p=K%86400 r=p%3600 B=r%60 W=i(x,E)M=i(o,m)j=i(K,86400)D=i(p,3600)d=i(r,60)if V==l then if W>1 or W==0 then q=T.year else q=Q.year end if M>1 or M==0 then y=T.month else y=Q.month end if j>1 or j==0 then I=T.day else I=Q.day end if D>1 or D==0 then g=T.hour else g=Q.hour end if d>1 or d==0 then Z=T.minute else Z=Q.minute end if B>1 or B==0 then O=T.second else O=Q.second end elseif V==U then if W>1 or W==0 then q=u.year else q=s.year end if M>1 or M==0 then y=u.month else y=s.month end if j>1 or j==0 then I=u.day else I=s.day end if D>1 or D==0 then g=u.hour else g=s.hour end if d>1 or d==0 then Z=u.minute else Z=s.minute end if B>1 or B==0 then O=u.second else O=s.second end end return W..(q..(M..(y..(j..(I..(D..(g..(d..(Z..(B..O))))))))))end end end local function M(N)if string.find(tostring(N),"\037\112")~=nil then error("\084\070\077\058 \071\105\118\101\110 \115\101\099\111\110\100\115 \097\114\101 \110\111\116 \105\110 \105\110\116\101\103\101\114 \102\111\114\109\033")return false else return true end end local j={}function j.Convert(w,N,x,o)if type(N)=="\110\117\109\098\101\114"then local x=M(N)if x==false then return end elseif type(N)=="\115\116\114\105\110\103"then if tonumber(N)~=nil then N=tonumber(N)local x=M(N)if x==true then N=tonumber(N)else return end else error("\084\070\077\058 \071\105\118\101\110 \115\116\114\105\110\103 \102\111\114 \115\101\099\111\110\100\115 \105\115 \110\111\116 \118\097\108\105\100\046 \080\108\101\097\115\101 \109\097\107\101 \115\117\114\101 \116\104\101 \103\105\118\101\110 \115\116\114\105\110\103 \104\097\115 \097 \110\117\109\098\101\114 \105\110 \105\116\033")return end else error("\084\070\077\058 \071\105\118\101\110 \115\101\099\111\110\100\115 \097\114\101 \110\111\116 \101\118\101\110 \097 \110\117\109\098\101\114 \111\114 \097 \118\097\108\105\100 \115\116\114\105\110\103\033")return end return W(N,x,o)end return j



local l = string.lower
local min, hr, d, mon, yr, max = "minute", "hour", "day", "month", "year", "max"
local secsInMonth, secsInYear = 2592000, 30672000
local default, colon, short, full = "default", "colon", "short", "full"
local a = {second = " sec ", minute = " min ", hour = " hr ", day = " d ", month = " mon ", year = " yr "}
local ap = {second = "sec ", minute = "mins ", hour = "hrs ", day = "d ", month = "mon ", year = "yrs "}
local f = {second = " second ", minute = " minute ", hour = " hour ", day = " day ", month = " month ", year = " year "}
local fp = {second = " seconds ", minute = " minutes ", hour = " hours ", day = " days ", month = " months ", year = " years "}

local function quickVar(secs, factor)
			
	return (secs - (secs % factor)) / factor
			
end

local function convert(secs, Form, addZero)
	
	local form
		
	if Form ~= nil then
		
		form = l(Form)
		
	else
		
		form = nil
		
	end
	
	if form == default or form == colon or form == nil then
		
		local remainderMin, remainderSecond, hour, minute = 0, 0, 0, 0

		if secs >= 3600 then
			
			remainderMin = secs % 3600
			remainderSecond = remainderMin % 60
			hour = quickVar(secs, 3600)
			minute = quickVar(remainderMin, 60)
			
		elseif secs < 3600 and secs >= 60 then
			
			remainderSecond = secs % 60
			minute = quickVar(secs, 60)
			
		else
			
			remainderSecond = secs
			minute = 0
			
		end
		
		if hour < 10 and addZero == true then
			
			hour = "0" .. hour
			
		end
		
		if (minute < 10 and secs >= 3600) or (minute < 10 and secs < 3600 and addZero == true) then
			
			minute = "0" .. minute
					
		end
		
		if (remainderSecond < 10 and secs >= 60) then
			
			remainderSecond = "0" .. remainderSecond
			
		end
		
		if secs < 60 then
			
			return secs
		
		elseif secs < 3600 and secs >= 60 then
			
			return minute .. ":" .. remainderSecond
		
		elseif secs >= 3600 then
			
			return hour .. ":" .. minute .. ":" .. remainderSecond
			
		end
		
	elseif form ~= default or form ~= nil or form ~= colon then
		
		if addZero == true then
			
			warn("TFM: Zeros are only togglable for the default form!")
			
		end
		
		local remainderYear, remainderMonth, remainderDay, remainderHour, remainderMin,remainderSecond, year, month, day, hour, minute = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
		local displayMin, displaySec, displayHr, displayDay, displayMon, displayYr
		
		if secs < 60 then
			
			if form == short then
				
				if secs > 1 then displaySec = ap.second else displaySec = a.second end
				
			elseif form == full then
				
				if secs > 1 then displaySec = fp.second else displaySec = f.second end
				
			end
			
			return secs .. displaySec
		
		elseif secs < 3600 then
			
			remainderSecond = secs % 60
			minute = quickVar(secs, 60)
						
			if form == short then
								
				if minute > 1 then displayMin = ap.minute else displayMin = a.minute end
				if remainderSecond > 1 then displaySec = ap.second else displaySec = a.second end
						
			elseif form == full then
				
				if minute > 1 then displayMin = fp.minute else displayMin = f.minute end
				if remainderSecond > 1 then displaySec = fp.second else displaySec = f.second end
									
			end
			
			return minute .. displayMin .. remainderSecond .. displaySec

		elseif secs < 86400 and secs >= 3600 then
			
			remainderMin = secs % 3600
			remainderSecond = remainderMin % 60
			hour = quickVar(secs, 3600)
			minute = quickVar(remainderMin, 60)
			
			if form == short then
				
				if hour > 1 then displayHr = ap.hour else displayHr = a.hour end
				if minute > 1 then displayMin = ap.minute else displayMin = a.minute end
				if remainderSecond > 1 then displaySec = ap.second else displaySec = a.second end
							
			elseif form == full then
				
				if hour > 1 then displayHr = fp.hour else displayHr = f.hour end
				if minute > 1 then displayMin = fp.minute else displayMin = f.minute end
				if remainderSecond > 1 then displaySec = fp.second else displaySec = f.second end
				
			end
			
			return hour .. displayHr .. minute .. displayMin .. remainderSecond .. displaySec
			
		elseif secs < secsInMonth and secs >= 86400 then
			
			remainderHour = secs % 86400
			remainderMin = remainderHour % 3600
			remainderSecond = remainderMin % 60
			day = quickVar(secs, 86400)
			hour = quickVar(remainderHour, 3600)
			minute = quickVar(remainderMin, 60)
			
			if form == short then
				
				if day > 1 or day == 0 then displayDay = ap.day else displayDay = a.day end
				if hour > 1 or hour == 0 then displayHr = ap.hour else displayHr = a.hour end
				if minute > 1 or minute == 0 then displayMin = ap.minute else displayMin = a.minute end
				if remainderSecond > 1 or remainderSecond == 0 then displaySec = ap.second else displaySec = a.second end
							
			elseif form == full then
				
				if day > 1 or day == 0 then displayDay = fp.day else displayDay = f.day end
				if hour > 1 or hour == 0 then displayHr = fp.hour else displayHr = f.hour end
				if minute > 1 or minute == 0 then displayMin = fp.minute else displayMin = f.minute end
				if remainderSecond > 1 or remainderSecond == 0 then displaySec = fp.second else displaySec = f.second end
				
			end
			
			return day .. displayDay .. hour .. displayHr .. minute .. displayMin .. remainderSecond .. displaySec
			
		elseif secs < secsInYear and secs >= secsInMonth then
			
			remainderDay = secs % secsInMonth
			remainderHour = remainderDay % 86400
			remainderMin = remainderHour % 3600
			remainderSecond = remainderMin % 60
			month = quickVar(secs, secsInMonth)
			day = quickVar(remainderDay, 86400)
			hour = quickVar(remainderHour, 3600)
			minute = quickVar(remainderMin, 60)
			
			if form == short then
				
				if month > 1 or month == 0 then displayMon = ap.month else displayMon = a.month end
				if day > 1 or day == 0 then displayDay = ap.day else displayDay = a.day end
				if hour > 1 or hour == 0 then displayHr = ap.hour else displayHr = a.hour end
				if minute > 1 or minute == 0 then displayMin = ap.minute else displayMin = a.minute end
				if remainderSecond > 1 or remainderSecond == 0 then displaySec = ap.second else displaySec = a.second end
							
			elseif form == full then
				
				if month > 1 or month == 0 then displayMon = fp.month else displayMon = f.month end
				if day > 1 or day == 0 then displayDay = fp.day else displayDay = f.day end
				if hour > 1 or hour == 0 then displayHr = fp.hour else displayHr = f.hour end
				if minute > 1 or minute == 0 then displayMin = fp.minute else displayMin = f.minute end
				if remainderSecond > 1 or remainderSecond == 0 then displaySec = fp.second else displaySec = f.second end
				
			end
			
			return month .. displayMon .. day .. displayDay .. hour .. displayHr .. minute .. displayMin .. remainderSecond .. displaySec
		
		elseif secs >= secsInYear then
			
			remainderMonth = secs % secsInYear
			remainderDay = remainderMonth % secsInMonth
			remainderHour = remainderDay % 86400
			remainderMin = remainderHour % 3600
			remainderSecond = remainderMin % 60
			year = quickVar(secs, secsInYear)
			month = quickVar(remainderMonth, secsInMonth)
			day = quickVar(remainderDay, 86400)
			hour = quickVar(remainderHour, 3600)
			minute = quickVar(remainderMin, 60)
			
			if form == short then
				
				if year > 1 or year == 0 then displayYr = ap.year else displayYr = a.year end
				if month > 1 or month == 0 then displayMon = ap.month else displayMon = a.month end
				if day > 1 or day == 0 then displayDay = ap.day else displayDay = a.day end
				if hour > 1 or hour == 0 then displayHr = ap.hour else displayHr = a.hour end
				if minute > 1 or minute == 0 then displayMin = ap.minute else displayMin = a.minute end
				if remainderSecond > 1 or remainderSecond == 0 then displaySec = ap.second else displaySec = a.second end
							
			elseif form == full then
				
				if year > 1 or year == 0 then displayYr = fp.year else displayYr = f.year end
				if month > 1 or month == 0 then displayMon = fp.month else displayMon = f.month end
				if day > 1 or day == 0 then displayDay = fp.day else displayDay = f.day end
				if hour > 1 or hour == 0 then displayHr = fp.hour else displayHr = f.hour end
				if minute > 1 or minute == 0 then displayMin = fp.minute else displayMin = f.minute end
				if remainderSecond > 1 or remainderSecond == 0 then displaySec = fp.second else displaySec = f.second end
				
			end
			
			return year .. displayYr .. month .. displayMon .. day .. displayDay .. hour .. displayHr .. minute .. displayMin .. remainderSecond .. displaySec
			
		end		
		
	end
	
end

local function checkSec(secs)
	
	if string.find(tostring(secs), "%p") ~= nil then
				
		error("TFM: Given seconds are not in integer form!")
		return false
		
	else
		
		return true
				
	end
	
end

local tfm = {}

	function tfm:Convert(secs, form, addZero)		
		
		if type(secs) == "number" then
			
			local passed = checkSec(secs)
			
			if passed == false then
				
				return
				
			end
			
		elseif type(secs) == "string" then
			
			if tonumber(secs) ~= nil then
				
				secs = tonumber(secs)
				local passed = checkSec(secs)
				
				if passed == true then
					
					secs = tonumber(secs)
					
				else
					
					return
					
				end
			
			else
				
				error("TFM: Given string for seconds is not valid. Please make sure the given string has a number in it!")
				return
				
			end
			
		else
			
			error("TFM: Given seconds are not even a number or a valid string!")
			return
		
		end
		
		return convert(secs, form, addZero)
		
	end

return tfm
