Module:time
Itsura
- This module lacks a documentation subpage. Please create it.
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
local language = mw.getContentLanguage()
local function format(code, timestamp)
return language:formatDate(code, timestamp)
end
local sub = mw.ustring.sub
local gsub = mw.ustring.gsub
local abbrs = {
["a."] = { anchor = "a.", full = "ante", },
["c."] = { anchor = "c.", full = "circa", },
["p."] = { anchor = "p.", full = "post", },
}
function export.quote(frame)
local params = {
["year"] = {},
["month"] = {},
["date"] = {},
["start_date"] = {},
["start_year"] = {},
["nodate"] = { type = boolean, default = false },
["accessdate"] = {},
["origdate"] = {},
["origyear"] = {},
["origmonth"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params, true)
local output = {}
local namespace = mw.title.getCurrentTitle().nsText
local start_date, date = args.start_date, args.date
--[[ "1 January, 2015", with day of the month before month name
and a comma, is not a valid date format; formatDate will
ignore the year "2015" and replace it with the current year.
The comma therefore has to be removed. ]]
if start_date then
start_date = gsub(start_date, "(%d+ %a+),", "%1")
end
if date then
date = gsub(date, "(%d+ %a+),", "%1")
end
local function insert(text)
table.insert(output, text)
end
if args.year then
local prefix = sub(args.year, 1, 2)
local abbr = abbrs[prefix]
if abbr then
insert('\'\'[[Appendix:Glossary#' .. abbr.anchor .. '|<abbr title="' .. abbr.full .. '">' .. abbr.anchor .. '</abbr>]]\'\' ')
-- [[Special:WhatLinksHere/Template:tracking/quote/abbr]]
require("Module:debug").track("quote/abbr")
-- Remove lowercase letter, period, and space from beginning of year parameter.
args.year = gsub(args.year, "%l.%s*", "")
end
if start_date then
if format("Y", start_date) == args.year then
if format("F", start_date) == args.month then
insert(
format("'''Y''' F j", start_date)
.. "–" .. date
)
else
insert(
format("'''Y''' F j",
start_date)
.. " – " .. args.month .. " " .. date
)
end
end
else
if args.month then
if args.start_year then
insert(
"'''" .. args.start_year
.. "''' – "
)
end
insert(
"'''" .. args.year .. "''' "
.. args.month
)
if date then
insert(" " .. date)
end
else
if args.start_year then
insert("'''" .. args.start_year .. "'''–")
end
insert("'''" .. args.year .. "'''")
end
end
else
if date then
if start_date then
if format("Y", start_date) == format("Y", date) then
if format("n", start_date) == format("n", date) then
insert(
format("'''Y''' F j", start_date)
.. "–" .. format("j", date)
)
else
insert(
format("'''Y''' F j", start_date)
.. "–" .. format("F j", date)
)
end
else
insert(
format("'''Y''' F j", start_date)
.. "–" .. format("'''Y''' F j", date)
)
end
else
insert(
format("'''Y''' F j", date)
)
end
else
if not args.nodate then
if args.accessdate then
insert(
format("'''Y''' F j", args.accessdate)
.. " (last accessed)"
)
else
if namespace ~= "Template" then
insert(
frame:expandTemplate{ title = "rfdate" }
)
end
end
end
end
end
return table.concat(output)
end
return export