-- This module takes a list of dates and adds a marker highlighting the closest-- date in the future.
local p = local lang = mw.language.getContentLanguage
local function normalizeDate(timestamp) local success, date = pcall(lang.formatDate, lang, 'Y-m-d', timestamp) return success and dateend
local function makeData(args) local data, unsorted =, for k, v in pairs(args) do if type(k)
'item' or datakey
local function makeComparisonDate(gracePeriod) local timestamp if gracePeriod then timestamp = 'now - ' .. gracePeriod else timestamp = 'now' end local date = normalizeDate(timestamp) if date then return date else error(string.format("invalid grace period '%s'", gracePeriod), 3) endend
local function makeHighlighter(color) color = color or '#FC6' local highlighter = mw.html.create('span') highlighter :css('background-color', color) :wikitext(lang:getArrow('forwards')) return tostring(highlighter)end
function p._main(args) local data = makeData(args) local comparisonDate = makeComparisonDate(args.graceperiod) local highlighter = args.highlighter or makeHighlighter(args.highlightercolor) local root = mw.html.create('ul') root :addClass(args.class) :cssText(args.style) local doneHighlight = false for i, t in ipairs(data) do local item if not doneHighlight and t.date >= comparisonDate then doneHighlight = true item = highlighter .. ' ' .. t.item else item = t.item end root :newline :tag('li') :wikitext(item) end root:newline return tostring(root)end
function p.main(frame) local args = require('Module:Arguments').getArgs(frame,) return p._main(args)end
return p