2,875
edits
No edit summary |
(Add seconds to timespan conversion) |
||
Line 199: | Line 199: | ||
error(msg) | error(msg) | ||
end | end | ||
end | |||
--- Creates a TimeSpan object from seconds. | |||
-- @param str (number) The amount of seconds to convert to a TimeSpan | |||
-- @return (TimeSpan) A TimeSpan object containing the seconds, minutes, hours and days the input amount of seconds amounts to. | |||
function p.secondsToTimeSpan(totalSeconds) | |||
local days = math.floor(totalSeconds / 86400) | |||
local remainder = totalSeconds % 86400 | |||
local hours = math.floor(remainder / 3600) | |||
remainder = remainder % 3600 | |||
local minutes = math.floor(remainder / 60) | |||
local seconds = remainder % 60 | |||
return { | |||
days = days, | |||
hours = hours, | |||
minutes = minutes, | |||
seconds = seconds, | |||
totalDays = totalSeconds / 86400, | |||
totalHours = totalSeconds / 3600, | |||
totalMinutes = totalSeconds / 60, | |||
totalSeconds = totalSeconds | |||
} | |||
end | end | ||
return p | return p |
edits