模块:Timebomb

AVMLOVER讨论 | 贡献2022年6月17日 (五) 10:14的版本 (AVMLOVER移动页面Module:Timebomb模块:Timebomb
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

require('Module:No globals') local getArgs = require('Module:Arguments').getArgs local lang = mw.language.new('en') local frame = mw.getCurrentFrame()

local p = { }

local function length(timebomb, compiled) local ts1 = lang:formatDate('U', timebomb) local ts2 = lang:formatDate('U', compiled)

return ts1 - ts2 end

local function fixed(timebomb, compiled) local length = length(timebomb, compiled) local clean = frame:callParserFunction('#dateformat:' .. timebomb)

if length < 0 and compiled then error('timebomb date is earlier than the compilation date') end

if compiled then local msg = mw.message.new('timebomb fixed') msg:params(clean, lang:formatDuration(length, {'days'})) return msg:plain() else return clean end end

local function dynamic(timebomb) local length = length(timebomb, 'now') local msg = mw.message.new('timebomb dynamic') msg:params(lang:formatDuration(length, {'days'})) return msg:plain() end

function p.main(frame) local args = getArgs(frame)

if not args.timebomb then return "" end

if args.timebomb:byte() == 43 then return dynamic(args.timebomb) else return fixed(args.timebomb, args.compiled) end end

return p