Module:ISOdate
From Neodyland Wiki
More actions
This documentation is transcluded from Module:ISOdate/doc.
local p = {}
function p.isodate(frame)
local input = frame.args[1]
local lang = frame.args["lang"]
-- Iteratively extract the parts
-- (We can't use one single pattern due to Lua restrictions)
local year = input:match( "^(%d+)" )
local month = input:match( "^%d+-(%d+)" )
local day = input:match( "^%d+-%d+-(%d+)" )
local hour = input:match( "^%d+-%d+-%d+ (%d+)" )
local minute = input:match( "^%d+-%d+-%d+ %d+:(%d+)" )
local second = input:match( "^%d+-%d+-%d+ %d+:%d+:(%d+)" )
-- {{date|year|month|day|form=|class=}}
local retval = frame:expandTemplate{ title="date", args={
[1]=year,
[2]=month,
[3]=day,
["form"]=frame.args["form"],
["class"]=frame.args["class"]
} }
-- Handle the time
if hour ~= nil and minute ~= nil then
retval = retval .. ", "
if lang == "ml-old"
or lang == "mn"
or lang == "te"
or lang == "th"
then
-- Unfortunately these require more complicated parsing
local formattedHour = frame:callParserFunction( "#time", { "H", input, lang } )
local formattedMin = frame:callParserFunction( "#time", { "i", input, lang } )
local formattedSec = frame:callParserFunction( "#time", { "s", input, lang } )
retval = retval
.. frame:expandTemplate{ title="formatnum4", args={ formattedHour } }
.. frame:expandTemplate{ title="formatnum4", args={ formattedMin } }
.. frame:expandTemplate{ title="formatnum4", args={ formattedSec } }
else
local separator = ":"
-- If necessary, choose a different separator
if lang == "sl" then
separator = "."
end
local format = "H" .. separator .. "i"
if second ~= nil then
format = format .. separator .. "s"
end
if lang == "bn"
or lang == "bpy"
or lang == "kn"
or lang == "hi"
or lang == "mr"
or lang == "new"
or lang == "pa"
or lang == "gu"
or lang == "lo"
or lang == "or"
or lang == "bo"
then
-- Do nothing
-- These languages are handled by {{#time}} directly
elseif lang == "ckb"
or lang == "ks"
or lang == "arabic-indic"
then
lang = "ks"
elseif lang == "fa"
or lang == "glk"
or lang == "mzn"
or lang == "ur"
then
lang = "fa"
else
-- Other languages just reset to nil
lang = nil
end
-- {{#time: format|input|lang}}
retval = retval .. frame:callParserFunction( "#time", { format, input, lang } )
end
end
return retval
end
return p