Module:GameLanding/Upcoming matches: Difference between revisions

From TwogPedia
(Created page with "local cargo = mw.ext.cargo local p = {} local getTeamLogo = require('Module:Functions').getTeamLogo local prizeToString = require('Module:Functions').prizeToString function p.upcomingMatches(game) local tables = 'AllMatches' local fields = '_pageName, date, p1, p2, winner' local currentDate = os.date('%Y-%m-%d') local cargoArgs = { where = '_pageName LIKE "' .. game .. '/%" AND ( date > "' .. currentDate .. '" OR winner=0)', orderBy = 'date ASC', limit = 10...")
 
mNo edit summary
Line 1: Line 1:
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo
local p = {}
local p = {}
local getTeamLogo = require('Module:Functions').getTeamLogo
local Functions = require('Module:Functions')
local prizeToString = require('Module:Functions').prizeToString
local getTeamLogo = Functions.getTeamLogo
local prizeToString = Functions.prizeToString
local timeUntil = Functions.timeUntil




Line 31: Line 33:
local team2 = mw.html.create('div')
local team2 = mw.html.create('div')
local currentDate = os.time() -- Get the current Unix timestamp
time:wikitext(timeUntil(result.date))
local dateString = result.date
 
-- Parse the date string into a table
local year, month, day, hour, minute, second = dateString:match("(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)")
-- Create a table with the parsed date and time
local targetDate = {
    year = tonumber(year),
    month = tonumber(month),
    day = tonumber(day),
    hour = tonumber(hour),
    min = tonumber(minute),
    sec = tonumber(second)
}
-- Convert the target date and time to a Unix timestamp
local targetTimestamp = os.time(targetDate)
-- Calculate the time difference in seconds
local timeDifference = targetTimestamp - currentDate
if timeDifference <= 0 then
time:wikitext('LIVE')
else
-- Calculate days, hours, and minutes
local days = math.floor(timeDifference / (24 * 3600))
local hours = math.floor((timeDifference % (24 * 3600)) / 3600)
local minutes = math.floor((timeDifference % 3600) / 60)
local timeUntil = string.format("%dd %dh %dm", days, hours, minutes)
time:wikitext(timeUntil)
end
team1:node(mw.html.create('div'):addClass('transfer__player'):node(getTeamLogo(result.p1, game)):node('[[' .. result.p1 .. '|' .. string.gsub(result.p1, game .. '/', '') .. ']]'))
team1:node(mw.html.create('div'):addClass('transfer__player'):node(getTeamLogo(result.p1, game)):node('[[' .. result.p1 .. '|' .. string.gsub(result.p1, game .. '/', '') .. ']]'))

Revision as of 08:38, 9 October 2023

Documentation for this module may be created at Module:GameLanding/Upcoming matches/doc

local cargo = mw.ext.cargo
local p = {}
local Functions = require('Module:Functions')
local getTeamLogo = Functions.getTeamLogo
local prizeToString = Functions.prizeToString
local timeUntil = Functions.timeUntil


function p.upcomingMatches(game)
	local tables = 'AllMatches'
	local fields = '_pageName, date, p1, p2, winner'
	local currentDate = os.date('%Y-%m-%d')
	local cargoArgs = {
		where = '_pageName LIKE "' .. game .. '/%" AND ( date > "' .. currentDate .. '" OR winner=0)',
		orderBy = 'date ASC',
		limit = 10
	}
	local results = cargo.query(tables, fields, cargoArgs)

	if #results > 0 then
		local list = ''
		local header = mw.html.create('div'):addClass('transfer__header transfer__row'):node(mw.html.create('div'):wikitext('Time')):node(mw.html.create('div'):wikitext('Team 1')):node(mw.html.create('div'):wikitext('')):node(mw.html.create('div'):wikitext('Team 2'))
		local wrapper = mw.html.create('div'):addClass('transfer__container'):node(header)
		local header = mw.html.create('div'):addClass('transfer__header'):node(mw.html.create('div'):wikitext('Time')):node(mw.html.create('div'):wikitext('Team 1')):node(mw.html.create('div'):wikitext('')):node(mw.html.create('div'):wikitext('Team 2'))
		local container = mw.html.create('div'):addClass('box__container'):node(mw.html.create('div'):addClass('box__title'):wikitext('Upcoming matches')):node(wrapper)

		for i = 1, #results do
			local result = results[i]
			local row = mw.html.create('div'):addClass('transfer__row')
			local time = mw.html.create('div')
			local team1 = mw.html.create('div')
			local vs = mw.html.create('div'):wikitext('[[' .. result._pageName .. '|vs]]')
			local team2 = mw.html.create('div')
			
			time:wikitext(timeUntil(result.date))
			
			team1:node(mw.html.create('div'):addClass('transfer__player'):node(getTeamLogo(result.p1, game)):node('[[' .. result.p1 .. '|' .. string.gsub(result.p1, game .. '/', '') .. ']]'))
			team2:node(mw.html.create('div'):addClass('transfer__player'):node(getTeamLogo(result.p2, game)):node('[[' .. result.p2 .. '|' .. string.gsub(result.p2, game .. '/', '') .. ']]'))
			
			row:node(time):node(team1):node(vs):node(team2)
			
			wrapper:node(row)
		end
		
		
		return container
	end
	return nil
end

return p