Module:Date

local p = {} local monthData = mw.loadData( 'Module:Month/data' ) local h = require("Module:HF") local getArgs = require('Dev:Arguments').getArgs local language = mw.language.new('en') local monthAliases = monthData[1] local monthNumbers = monthData[2]

-- return full month name function p.month(frame) local args = getArgs(frame) local name = mw.text.trim(args[1]) local output = monthAliases[ string.lower(name) ] return output or name end

-- return month number function p.monthNumber(frame) local args = getArgs(frame) local number = mw.text.trim(args[1]) local output = monthNumbers[ string.lower(number) ] return output or number end

--takes a date and formats it according to the syntax - https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions##time function p.lua_date_converter(s_date, s_format) local s = {} --1 = year, 2 = month, 3 = day local i = 0 local j = 0 local output = '' --'To comma' = 'F j, Y', "dash" = 'm-d-Y' s_format = s_format or 'Ymd'

if h.isempty(s_date) then output = language:formatDate(s_format) else i = string.find(s_date, '-',1,true) j = string.find(s_date, ', ',1,true) if i ~= nil then j = string.find(s_date, '-',i+1,true) s[2] = p.month({ string.sub(s_date, 1, i-1) }) s[3] = string.sub(s_date, i+1, j-1) if #s[3] == 1 then s[3] = '0'..s[3] end s[1] = string.sub(s_date, j+1, #s_date) output = language:formatDate(s_format, s[2]..' '..s[3]..' '..s[1]) elseif j ~= nil then s[1] = string.sub(s_date, j+2, #s_date) i = string.find(s_date, ' ',1,true) s[2] = p.month({ string.sub(s_date, 1, i-1) }) s[3] = string.sub(s_date, i+1, j-1) if #s[3] == 1 then s[3] = '0'..s[3] end output = language:formatDate(s_format, s[2]..' '..s[3]..' '..s[1]) else output = language:formatDate(s_format, s_date) end end return output end

--compares two dates. Return "true" if 1st date is before the 2nd date, and "false" otherwise. function p.lua_date_comparison(date1, date2) date1 = p.lua_date_converter(date1, 'Ymd') date2 = p.lua_date_converter(date2 or 'now', 'Ymd') --If 2nd date is ommited, then current date is used for comparison. return date1<=date2 end

--check if comics, episode, movie, etc. was recently released/published function p.isRecent(frame) local current = p.lua_date_converter local args = getArgs(frame) local output = false local s = '-4 months' local releasedate = args['releasedate'] local year = args['year'] local month = args['month'] local season = args['season'] local canceled = args['canceled'] or false

if not canceled and ( not h.isempty(releasedate) or not h.isempty(year) ) then if not h.isempty(releasedate) then releasedate = p.lua_date_converter(releasedate, 'Ymd') else if h.isempty(month) then if h.isempty(season) then month = '1' else month = season end end month = p.month({month}) releasedate = p.lua_date_converter(month..' 01 '..year, 'Ymd') mw.log(releasedate) s = '-2 months' end s = language:formatDate('Ymd', s)           if not h.isempty(releasedate) and releasedate>=s and releasedate<=current then output = true end end return output end

--returns era based on year function p.getEra(frame) local args = getArgs(frame) local year = tonumber(args[1]) local key = args[2] or '' local output = ''

if not h.isempty(year) then if not h.isempty(key) then key = ' '..key end if year<1955 then output = 'Golden-Age'..key end if year>=1955 and year<1970 then output = 'Silver-Age'..key end if year>=1970 and year<1983 then output = 'Bronze-Age'..key end if year>=1983 and year<1992 then output = 'Copper-Age'..key end if year>=1992 then output = 'Modern-Age'..key end end return output end

return p