Module:Available

-- -- Lua script to display Latest Items Info on Main Page and Availability on Character/Attraction Page -- --

local p = {}

local availableData = mw.loadData( 'Module:Available/data' ) local lastLTE = require ("Module:LTEvent").getLastLTE local lastUpdate = require("Module:UpdateNumber").getLastVer local lastME = require("Module:MiniEvent").getLastME local upcomingME = require("Module:MiniEvent").getUpcomingME local util = require('Module:Utility') local date = require("Dev:Date")

local function strDate(sDate) local theDate = date(sDate)

return string.gsub(theDate:fmt("%d"), "^0", "") .. theDate:fmt(" %B %Y") end

local function lastCharacter(count) local limit = count local tIndex = {} if not limit or limit == 0 then limit = 3 end

local today = os.date("%Y/%m/%d") for idx, data in ipairs(availableData) do       if data[5] and data[3] and today >= data[3] then table.insert(tIndex, data) end end

table.sort(tIndex, function(a,b) return a[3] > b[3] end) local outText = "" --   for i, ver in ipairs(tIndex) do --        outText = outText .. singleEvent(ver[2], ver[3], "L", "") --       if i >= count then break end --   end

local retText = "" for i, v in ipairs(tIndex) do       local today = os.date("%Y/%m/%d")

local linkText = v[1] and "" or "Work In Progress"

if v[2] then linkText = ""                       .. (v[1] or "")                        .. "" else local space = ""

for cName in mw.text.gsplit(v[1], "%s*%$%s*") do               linkText = linkText .. space .. "" .. cName .. "" space = ", " end end

retText = retText .. "* "               .. linkText .. " "               .. strDate(v[3]) .. " \n"

if i>= limit then break end end return retText end

function p.latest(frame) local tArgs = util.getArgs(frame)

local headerlast = '{| class="article-table" width="100%"\n' ..	'! style="vertical-align:top;"|\n' local headerupcoming = '{| class="article-table" width="100%"\n' ..	  '! style="vertical-align:top; border: 3px solid #F94444;"|\n' local foot1 = '' .. ' For '

local foot2 = '|here]] \n|}\n'

local outText = "==Upcoming Events ==\n" .. headerupcoming .. upcomingME({"5"}) .. foot1 .. "a complete timeline of the events in Disney Magic Kingdoms, click [[Event Timeline"                   .. foot2

outText = outText .. '{| class="" style="background-color:transparent;'                   .. ' color:inherit; width:100%;"\n' .. '|-\n' .. '| valign="top" style="width:50%;" |\n\n' outText = outText .. "==Latest Major Events==\n" .. headerlast .. lastLTE({"5"}) .. foot1 .. "more events, click [[:Category:Events"                   .. foot2

outText = outText .. "==Latest Mini Events==\n" .. headerlast .. lastME({"5"}) .. foot1 .. "more mini events, click [[:Category:Mini Events"                   .. foot2

outText = outText .. '\n| valign="top" style="width:50%;" |\n\n'

outText = outText .. "==Latest Updates==\n" .. headerlast .. lastUpdate({"5"}) .. foot1 .. "more updates, click [[Content Updates"                   .. foot2

outText = outText .. "==Latest Characters==\n" .. headerlast .. lastCharacter(5) .. foot1 .. "more characters, click [[:Category:Character Collections"                   .. foot2

outText = outText .. "|}\n"

return outText end

local function dispTime(t) local d = math.floor(t / 86400) local h = math.floor((t % 86400) / 3600) local m = math.floor((t % 3600) / 60) if d == 0 and h == 0 then return string.format("%dm", m)	elseif d == 0 then return string.format("%dh %02d", h, m)	else return string.format("%dd %dh %02d", d, h, m)	end end

local function countdown(enddate, text1, text2, post_text) return "" .. text1 .. "" .. enddate .. " "       	.. text2 .. " " .. post_text .. " " end

function p.availability(frame) local tArgs = util.getArgs(frame) if not tArgs[1] then tArgs[1] = mw.title.getCurrentTitle.text end local today = os.date("%Y/%m/%d %H:%M:%S")

for idx, data in ipairs(availableData) do   	if data[2] == nil then for cName in mw.text.gsplit(data[1], "%s*%$%s*") do local UnlockDate = data[3] .. util.dayStart local LockDate = date(data[3]):adddays(data[4]):fmt("%Y/%m/%d") .. (data[6] or util.dayStart) if tArgs[1] == cName and today <= UnlockDate then return countdown(UnlockDate,   					" ''(Available in ", ")''",   					""    					)				elseif tArgs[1] == cName and today <= LockDate then return countdown(LockDate,   					" ''(Available for ", ")''",   					""    					)				elseif tArgs[1] == cName then return "" end end end end

local itemData = mw.loadData( 'Module:ItemCollection/data' ) if itemData["Items"][tArgs[1]] and itemData["Items"][tArgs[1]][4] and itemData["Items"][tArgs[1]][4] == true then return "" else return "" end end

return p