Documentation for this module may be created at Module:User timezone/doc
-- This module implements [[Template:User timezone]]
local p = {}
-- Ordered list of flag parameters and the label each should print.
local zones = {}
for i = 12, 1, -1 do
zones[#zones + 1] = { param = 'UTC-' .. i, label = 'UTC-' .. i }
end
zones[#zones + 1] = { param = 'UTC', label = 'UTC' }
for i = 1, 14 do
zones[#zones + 1] = { param = 'UTC' .. i, label = 'UTC+' .. i }
end
local function isSet( v )
return v ~= nil and mw.text.trim( v ) ~= ''
end
-- Explicit |zone= wins; otherwise the first flag that's set.
local function resolveZone( args )
if isSet( args.zone ) then
return mw.text.trim( args.zone )
end
for _, z in ipairs( zones ) do
if isSet( args[ z.param ] ) then
return z.label
end
end
return nil
end
function p.render( frame )
local args = frame:getParent().args
local zone = resolveZone( args )
local zonename = isSet( args.zonename ) and mw.text.trim( args.zonename ) or nil
local body = "This user's '''time zone''' is '''" .. ( zone or 'unknown' ) .. "'''."
if zonename then
body = body .. '<br />' .. frame:expandTemplate{ title = 'C', args = { zonename } }
end
local box = frame:expandTemplate{
title = 'Userbox',
args = { '#996633', '#35230F', '[[Image:clock2uk.png|40px]]', body },
}
-- The docs promise a category. Now it's one line to actually deliver one.
if zone and mw.title.getCurrentTitle().namespace == 2 then
box = box .. '[[Category:' .. zone .. ' users]]'
end
return box
end
return p