Halo Esports Wiki

We are currently performing extensive maintenance to this wiki and as a result there will likely be errors. Please be patient while we work to fix all problems.

READ MORE

Halo Esports Wiki
Advertisement

Documentation for this module may be created at Module:TimedeltaUtil/doc

local util_args = require("Module:ArgsUtil")
local util_time = require("Module:TimeUtil")
local util_vars = require("Module:VarsUtil")

local Seconds = require('Module:TimedeltaAbstract'):extends()
local Display = require('Module:TimedeltaAbstract'):extends()

local SECONDS_PER_DAY = 24 * 60 * 60
Display.outputUnknown = '??'
Seconds.outputUnknown = -1
Display.fuzzyPrefix = '≈'
Seconds.fuzzyPrefix = ''
Display.lessThanOneYear = '<1y'
Seconds.lessThanOneYear = 365 * SECONDS_PER_DAY
Display.lessThan = '≤'
Seconds.lessThan = ''
Display.clarifyApprox = '??'
Seconds.clarifyApprox = ''

function Display:lessThanOneMonth(days) return '<1m' end
function Seconds:lessThanOneMonth(days)
	return days * SECONDS_PER_DAY
end

function Seconds:approxDurationExact(sDate, eDate)
	return os.difftime(util_time.unix(eDate), util_time.unix(sDate))
end

function Seconds:addFuzzyPrefixIffNeeded(ret) return ret end

local p = {}

function p.test(frame)
	local args = util_args.merge()
	s = args.s
	e = args.e
	return ('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>'):format(
		args.s,
		args.e,
		Display:main(args.s, args.e, util_args.castAsBool(args.fuzzy)),
		Seconds:main(args.s, args.e, util_args.castAsBool(args.fuzzy))
	)
end

function p.approxDurationDisplay(s, e, fuzzy)
	return Display:main(s, e, fuzzy)
end

function p.approxDurationSeconds(s, e, fuzzy)
	return Seconds:main(s, e, fuzzy)
end

function p.approxDurationDays(s, e, fuzzy)
	return Seconds:main(s, e, fuzzy) / SECONDS_PER_DAY
end

return p
Advertisement