Anonymous

Module:TimeSpan: Difference between revisions

From Melvor Idle
m
Slight improvements to toStringLong
(Add two toString functions)
m (Slight improvements to toStringLong)
Line 110: Line 110:


function TimeSpan:toStringLong()
function TimeSpan:toStringLong()
local sb = StringBuilder.new()
-- Fast path if there's less than a minute's worth of time.
local totalSeconds = self:getTotalSeconds()
if totalSeconds < 60 then
if math.floor(totalSeconds) == 0 then
return string.format('0 seconds')
end
return string.format('%.1f seconds', totalSeconds)
end
 
-- Long path that outputs the entire TimeSpan
local output = {}
local days = self:getDays()
local days = self:getDays()
local hours = self:getHours()
local hours = self:getHours()
Line 116: Line 127:
local seconds = self:getSeconds()
local seconds = self:getSeconds()
local milliseconds = self:getMilliseconds()
local milliseconds = self:getMilliseconds()
 
local output = {}
if days > 0 then
if days > 0 then
table.insert(output, string.format('%d day%s', days, (days > 1) and "s" or ""))
table.insert(output, string.format('%d day%s', days, (days > 1) and "s" or ""))
2,875

edits