Module:Timeline
From Landrace.wiki
More actions
Helpers for the timeline record: the timeline subobject that {{Infobox Archaeological site}}, {{Infobox Historical Source}} and {{Infobox Legal Instrument}} add to their pages, which the History map and timeline read.
Functions
{{#invoke:Timeline|year|1=…|2=…}}- The year of the first argument that is a single date, as a whole number, negative before the Common Era; empty when none is. Arguments are tried in number order, so a template lists its date fields in order of preference. Always name the arguments (
1=), because a value containing=would otherwise be lost. - Read as a single date:
1690,-1200,1200 BC,1200 BCE,1961-03-30,1961-03,15 September 1894,September 1894. - Not read: a range (
1893–1894), an approximate date (c. 1690), a century, or a sentence. These give nothing, so the next argument is tried. {{#invoke:Timeline|label|1=…}}- The argument, trimmed; where it is empty, the title of the page, without its namespace. The title is taken as plain text, so an apostrophe in it is stored as an apostrophe.
See also
-- Helpers for the timeline record: the {{#subobject:timeline}} that Infobox Archaeological site,
-- Infobox Historical Source and Infobox Legal Instrument emit for the History map and timeline.
local p = {}
local MONTHS = {
january = true, february = true, march = true, april = true, may = true, june = true,
july = true, august = true, september = true, october = true, november = true, december = true,
}
-- The year a single date stands for, as a whole number (negative before the Common Era), or nil.
-- Accepted: 1690 · -1200 · 1200 BC · 1200 BCE · 1961-03-30 · 1961-03 · 15 September 1894 · September 1894.
-- Anything else (a range, "c. 1690", "13th century", a sentence) is not a single date and gives nil.
function p._year(s)
s = mw.text.trim(s or '')
if s == '' then
return nil
end
local y = s:match('^(%-?%d+)$') or s:match('^(%-?%d+)%-%d%d$') or s:match('^(%-?%d+)%-%d%d%-%d%d$')
if y then
return tonumber(y)
end
y = s:match('^(%d+)%s*[Bb]%.?[Cc]%.?[Ee]?%.?$')
if y then
return -tonumber(y)
end
local month
month, y = s:match('^%d%d?%s+(%a+)%s+(%d+)$')
if not month then
month, y = s:match('^(%a+)%s+(%d+)$')
end
if month and MONTHS[month:lower()] then
return tonumber(y)
end
return nil
end
-- {{#invoke:Timeline|year|1=…|2=…}}: the year of the first argument that is a single date, else empty.
-- Arguments are tried in number order, so a template lists its date fields in order of preference.
function p.year(frame)
local args = frame.args
for i = 1, 10 do
local y = p._year(args[i])
if y and y ~= 0 then
return tostring(y)
end
end
return ''
end
-- {{#invoke:Timeline|label|1={{{timeline_label|}}}}}: the caption, or the page title when it is empty.
-- The title comes from mw.title, not {{PAGENAME}}, which would store an apostrophe as '.
function p.label(frame)
local s = mw.text.trim(frame.args[1] or '')
if s ~= '' then
return s
end
return mw.title.getCurrentTitle().text
end
return p