Module:Time: Difference between revisions
From Melvor Idle
(Created page with " -- 123 => 00:02:03 function p.secondsToHMS(s) local ONE_DAY = 24 * 60 * 60 if s > ONE_DAY then return string.format('%d day%s, ', s/ONE_DAY, (math.floor(s/ONE_DAY) > 1) and "s" or "") .. os.date("!%X", s) else return os.date("!%X", s) end end -- 123 => 2 minutes, 3 seconds function p.secondsToHuman(s) if s < 60 then if s > 0 or s < 0 then return string.format('%.1f seconds', s) else return string.format('0 seconds', s) end end local days = math.f...") |
No edit summary |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local p = {} | |||
local Number = require('Module:Number') | |||
function p. | local TimeSpan = require('Module:TimeSpan') | ||
local | |||
if | function p._secondsToHMS(totalSeconds) | ||
return string.format('%d day%s, ', | local days = math.floor(totalSeconds / (24 * 60 * 60)) | ||
if days >= 1 then | |||
return string.format('%d day%s, ', days, (days > 1) and "s" or "") .. os.date("!%X", totalSeconds) | |||
else | else | ||
return os.date("!%X", | return os.date("!%X", totalSeconds) | ||
end | end | ||
end | end | ||
function p._secondsToHuman(totalSeconds) | |||
function p. | local timeSpan = TimeSpan.fromSeconds(totalSeconds) | ||
return timeSpan:toStringLong() | |||
local | |||
return | |||
end | end | ||
function p. | function p.secondsToHuman(frame) | ||
local args = frame.args ~= nil and frame.args or frame | |||
return p._secondsToHuman(args[1]) | |||
return | |||
end | end | ||
return p | |||
Latest revision as of 20:52, 13 April 2024
Provides time helper functions that can be used elsewhere in the wiki
local p = {}
local Number = require('Module:Number')
local TimeSpan = require('Module:TimeSpan')
function p._secondsToHMS(totalSeconds)
local days = math.floor(totalSeconds / (24 * 60 * 60))
if days >= 1 then
return string.format('%d day%s, ', days, (days > 1) and "s" or "") .. os.date("!%X", totalSeconds)
else
return os.date("!%X", totalSeconds)
end
end
function p._secondsToHuman(totalSeconds)
local timeSpan = TimeSpan.fromSeconds(totalSeconds)
return timeSpan:toStringLong()
end
function p.secondsToHuman(frame)
local args = frame.args ~= nil and frame.args or frame
return p._secondsToHuman(args[1])
end
return p