Module:Time: Difference between revisions

From Melvor Idle
mNo edit summary
No edit summary
 
Line 19: Line 19:


function p.secondsToHuman(frame)
function p.secondsToHuman(frame)
local args = frame:getParent().args
local args = frame.args ~= nil and frame.args or frame
return p._secondsToHuman(args[1])
return p._secondsToHuman(args[1])
end
end


return p
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