Module:News

local p = {} local today = os.date('!*t') local lang = mw.language.new('en') local maxMonthAge = 4 -- older than this will not be displayed

function isNewsPage return mw.title.getCurrentTitle == 'Hitler Parody Wiki:News' end

-- no fuss way to generate date table function makeDate(y, m, d)  return os.date('!*t', lang:formatDate( 'U', y..'-'..m..'-'..d ) ) end

-- returns date table function parseDate(s) return os.date('!*t', lang:formatDate( 'U', s ) ) end

function monthDiff(d1, d2) local baseyear = 2000 local m1 = (d1.year - baseyear) * 12 + d1.month local m2 = (d2.year - baseyear) * 12 + d2.month return math.abs(m2 - m1) end

-- compares the months and determine if news item is old function isOld(d1) return monthDiff(d1, today)>maxMonthAge end

function h2(s) return ' ' ..s.. ' ' end

function h3(s) return ' ' ..s.. ' ' end

-- takes a table of strings and returns a HTML ul function table2ul(t) if tablelength(t) == 0 then return '' end if type(t) == 'string' then return t end local s = {} table.insert(s, '') for _,v in pairs(t) do       table.insert(s, '' .. v .. '') end table.insert(s, '') return table.concat(s) end

-- MODULE METHODS -- year header function p.h2(frame) local d = makeDate(args[1], 12, 31) -- take as end of year if not isOld(d) then return h2(frame.args[1]) end end

-- month header function p.h3(frame) local d = parseDate(frame.args[1]) if not isOld(d) then return h3(frame.args[1]) end end

-- the main method -- args[date]: the news date -- args[n]: items in the news for the above date function p.item(frame) local dateStr = frame.args[date] local dateTbl = os.date( '!*t', dateStr ) -- waiting for response at dev.wikia.com/wiki/Thread:11286 end

return p