Module:Last Featured

local p = {} local lib = require('Module:Feature') local TableTools = require('Module:TableTools') local parseDateTime = require('Module:Event List').parseDateTime local time_ago = require('Module:Time Ago').main

function p.main(frame) local args = require('Module:Arguments').getArgs(frame, {		parentFirst = true	}) if frame.args.wishes then args.wishes = frame.args.wishes end return p._main(args) end

function p._main(args) if (lib.isEmpty(args.wishes)) then return '' end -- Parse input. local wishes = lib.parseTemplateFormat(args.wishes) -- Return if empty if (TableTools.size(wishes) == 0) then return '' end local data = { prev_run = {}, curr_run = {}, next_run = {}, unkn_run = {}, }	local time_curr = os.time -- Organize wishes into data. for i, wish in ipairs(wishes) do		if (wish.time_known == 'no' or wish.duration == 'unknown') then table.insert(data.unkn_run, wish) elseif (wish.time_known == 'yes' or (lib.isNotEmpty(wish.time_start) and lib.isNotEmpty(wish.time_end))) then local time_start = parseDateTime(wish.time_start, lib.ternary( lib.isNotEmpty(wish.time_start_offset), wish.time_start_offset, 'GMT+8' ))			local time_end = parseDateTime(wish.time_end, lib.ternary( lib.isNotEmpty(wish.time_end_offset), wish.time_end_offset, 'GMT-5' ))			wish.time_start = wish.time_start .. lib.ternary(lib.isNotEmpty(wish.time_start_offset), wish.time_start_offset, 'GMT+8') wish.time_end = wish.time_end .. lib.ternary(lib.isNotEmpty(wish.time_end_offset), wish.time_end_offset, 'GMT-5') if (wish.time_end == 'none') then mw.log('impoosible') elseif (time_end < time_curr) then table.insert(data.prev_run, wish) elseif (time_start < time_curr and time_end > time_curr) then table.insert(data.curr_run, wish) elseif (time_start > time_curr) then table.insert(data.next_run, wish) else table.insert(data.unkn_run, wish) end elseif (wish.time_known == 'yes' or lib.isNotEmpty(wish.time_start)) then local time_start = parseDateTime(wish.time_start, lib.ternary( lib.isNotEmpty(wish.time_start_offset), wish.time_start_offset, 'GMT+8' ))			wish.time_start = wish.time_start .. lib.ternary(lib.isNotEmpty(wish.time_start_offset), wish.time_start_offset, 'GMT+8') if (wish.time_end == 'none') then mw.log('impoosible') elseif (time_start > time_curr) then table.insert(data.next_run, wish) else table.insert(data.unkn_run, wish) end else table.insert(data.unkn_run, wish) end end -- Create result. local result = '' if (TableTools.size(data.curr_run) > 0) then result = result .. 'Current: ' result = result .. 		result = result .. 'Ends ' .. time_ago{data.curr_run[1].time_end, include='y,mth,d', lowercase='1'} .. 		result = result .. '' end if (TableTools.size(data.prev_run) > 0) then if (result ~= '') then result = result .. ' ' end result = result .. 'Previous: ' result = result .. 		result = result .. 'Ran ' .. time_ago{data.prev_run[1].time_end, include='y,mth,d', lowercase='1'} .. 		result = result .. '' end if (TableTools.size(data.next_run) > 0) then if (result ~= '') then result = result .. ' ' end result = result .. 'Upcoming: ' result = result .. 		result = result .. 'Runs ' .. time_ago{data.next_run[1].time_start, include='y,mth,d', lowercase='1'} .. 		result = result .. '' end if (TableTools.size(data.unkn_run) > 0) then if (result ~= '') then result = result .. ' ' end result = result .. 'Upcoming (Date Unknown): ' result = result ..  .. data.unkn_run[1].page ..  end return result

end

return p