![]() | This module is rated as alpha. It is ready for third-party input, and may be used on a few pages to see if problems arise, but should be watched. Suggestions for new features or changes in their input and output mechanisms are welcome. |
![]() | This module depends on the following other modules: |
This module implements Template:Calendar date (talk · links · edit).
Usage
{{#invoke:Calendar date|function_name}}
--[[
Display non-Gregorian holiday dates using equivalent Gregorian date
]]
local p = {}
--[[--------------------------< inlineError >-----------------------
Critical error. Render output completely in red. Add to tracking category.
]]
local function inlineError(arg, msg, tname)
track["Category:Holigreg template errors"] = 1
return '<span style="font-size:100%" class="error citation-comment">Error in [[Template:' .. tname .. ']] - Check <code style="color:inherit; border:inherit; padding:inherit;">|' .. arg .. '=</code> ' .. msg .. '</span>'
end
--[[--------------------------< trimArg >-----------------------
trimArg returns nil if arg is "" while trimArg2 returns 'true' if arg is ""
trimArg2 is for args that might accept an empty value, as an on/off switch like nolink=
]]
local function trimArg(arg)
if arg == "" or arg == nil then
return nil
else
return mw.text.trim(arg)
end
end
local function trimArg2(arg)
if arg == nil then
return nil
else
return mw.text.trim(arg)
end
end
--[[--------------------------< tableLength >-----------------------
Given a 1-D table, return number of elements
]]
local function tableLength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
--[[--------------------------< createTracking >-----------------------
Return data in track[] ie. tracking categories
]]
local function createTracking()
local sand = ""
if tableLength(track) > 0 then
for key,_ in pairs(track) do
sand = sand .. "[[" .. key .. "]]"
end
end
return sand
end
--[[--------------------------< holigreg >-----------------------
Main function
]]
function p.holigreg(frame)
local pframe = frame:getParent()
local args = pframe.args
local tname = "Holigreg" -- name of calling template. Change if template rename.
local holiday = nil -- name of holiday
local date = nil -- date of holiday
track = {} -- global tracking-category table
--- Determine holiday
holiday = trimArg(args.holiday) -- required
if not holiday then
return inlineError("holiday", "Missing holiday argument", tname) .. createTracking()
end
--- Determine date
date = trimArg(args.date) -- required
if not date then
return inlineError("date", "Missing date argument", tname) .. createTracking()
end
local version = mw.title.makeTitle( 'Template', 'Holigreg/holidays/' .. holiday .. '.js' )
local json = mw.text.jsonDecode( version:getContent() )
return json.items[4].date
end
return p