Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Highlighted date list
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- 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 date end local function makeData(args) local data, unsorted = {}, {} for k, v in pairs(args) do if type(k) == 'string' then local datakey, num = k:match('^(.-)([1-9][0-9]*)$') if datakey == 'item' or datakey == 'date' then num = tonumber(num) unsorted[num] = unsorted[num] or {} unsorted[num][datakey] = v elseif datakey then error(string.format("invalid parameter '%s' detected", k), 3) end end end for num, t in pairs(unsorted) do if t.item and t.date then local date = normalizeDate(t.date) if not date then error(string.format( "invalid date '%s' in parameter 'date%d'", t.date, num ), 3) end t.date = date table.insert(data, t) elseif t.item then error(string.format( "parameter 'item%d' was specified but parameter 'date%d' is missing", num, num ), 3) else error(string.format( "parameter 'date%d' was specified but parameter 'item%d' is missing", num, num ), 3) end end table.sort(data, function (t1, t2) return t1.date < t2.date end) return data end 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) end end 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, { wrappers = 'Template:Highlighted date list' }) return p._main(args) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Tl
(
edit
)
Module:Highlighted date list/doc
(
edit
)