4,951
edits
Falterfire (talk | contribs) (contains now returns index of first) |
Falterfire (talk | contribs) (Added timeString function) |
||
Line 295: | Line 295: | ||
local gcd = p.gcd(n, d) | local gcd = p.gcd(n, d) | ||
return p.formatnum(n/gcd)..'/'..p.formatnum(d/gcd) | return p.formatnum(n/gcd)..'/'..p.formatnum(d/gcd) | ||
end | |||
function p.timeString(timeInSeconds) | |||
local remain = timeInSeconds | |||
local days, hours, minutes = 0, 0, 0 | |||
local pieces = {} | |||
if remain >= 86400 then | |||
days = math.floor(remain / 86400) | |||
remain = remain - days * 86400 | |||
if days > 1 then | |||
table.insert(pieces, days..' days') | |||
else | |||
table.insert(pieces, days..' day') | |||
end | |||
end | |||
if remain >= 3600 then | |||
hours = math.floor(remain / 3600) | |||
remain = remain - hours * 3600 | |||
if hours > 1 then | |||
table.insert(pieces, hours..' hours') | |||
else | |||
table.insert(pieces, hours..' hour') | |||
end | |||
end | |||
if remain >= 60 then | |||
minutes = math.floor(remain / 60) | |||
remain = remain - minutes * 60 | |||
if minutes > 1 then | |||
table.insert(pieces, minutes..' minutes') | |||
else | |||
table.insert(pieces, minutes..' minutes') | |||
end | |||
end | |||
if remain > 0 then | |||
if remain > 1 then | |||
table.insert(pieces, remain..' seconds') | |||
else | |||
table.insert(pieces, remain..' second') | |||
end | |||
end | |||
return table.concat(pieces, ', ') | |||
end | end | ||
return p | return p |