Module:ScheduleQueryAbstract

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_esports = require('Module:EsportsUtil') local util_form = require('Module:FormUtil') local util_html = require('Module:HtmlUtil') local util_table = require("Module:TableUtil") local util_text = require('Module:TextUtil') local util_time = require('Module:TimeUtil') local util_toggle = require('Module:ToggleUtil') local util_vars = require('Module:VarsUtil') local i18n = require("Module:I18nUtil") local LCS = require('Module:LuaClassSystem') local date = require('Module:Date') local m_team = require('Module:Team')

local p = LCS.class.abstract local h = {}

p.timezones = { 'PST', 'CET', 'KST' } p.toggles = { order = { 'me', 'general' }, displays = { me = 'Localized', general = 'Non-Localized' }, } p.columnToggles = { DateLocal = 'me', TimeLocal = 'me', PSTme = 'me', CETme = 'me', KSTme = 'me', Date1 = 'general', Date2 = 'general', PSTgen = 'general', CETgen = 'general', KSTgen = 'general', Countdown = 'me', } function p:init(page) i18n.init('ScheduleQueryAbstract') self.columns = { 'DateLocal', 'TimeLocal', 'PSTme', 'CETme', 'KSTme', 'Date1', 'Date2', 'PSTgen', 'CETgen', 'KSTgen', 'Countdown', } self.widths = { DateLocal = 120, TimeLocal = 120, PSTme = 120, CETme = 120, KSTme = 120, Date1 = 120, Date2 = 120, PSTgen = 40, CETgen = 40, KSTgen = 40, Countdown = 85, }	self.page = util_esports.getOverviewPage(page) end

function p:printToggler(tbl) local div = tbl:tag('div') :addClass('toggle-button') util_toggle.printOptionFromListTogglers(div, self.toggles) util_html.clear(tbl) end

function p:printWidthRow(tbl) local tr = tbl:tag('tr'):addClass('empty-width-row') for _, v in ipairs(self.columns) do local td = tr:tag('td'):css('width', v .. 'px'):wikitext(' ') if self.columnToggles[v] then util_toggle.oflCellClasses(td, self.toggles, self.columnToggles[v]) end end end

function p:printHeadings(tr) for _, v in ipairs(self.columns) do		local th = tr:tag('th'):wikitext(i18n.print(v)) if self.columnToggles[v] then util_toggle.oflCellClasses(th, self.toggles, self.columnToggles[v]) end end end

function p:printMatch(tr, row) local td = tr:tag('td') td:node(		util_html.vsAlign( m_team.leftshortlinked(row.Team1), m_team.rightshortlinked(row.Team2) )	)	return td end

function p:printDateAndTime(tr, row) if not row.UTC or row.UTC == '' then self:printTbdCell(tr, 6, 'me') self:printTbdCell(tr, 5, 'general') return end local td = tr:tag('td'):wikitext(util_time.dateInLocal(row.UTC)) util_toggle.oflCellClasses(td, self.toggles, 'me') if not row.HasTime then self:printTbdCell(tr, 4, 'me') self:printTbdCell(tr, 5, 'general') else local utc = tr:tag('td'):wikitext(util_time.timeInLocal(row.UTC)) util_toggle.oflCellClasses(utc, self.toggles, 'me') local tz_data = self:getTZData(row) self:addTZToRow(tr, tz_data) local dates = h.getAbsoluteDates(row.UTC) self:addAbsDates(tr, dates) self:addTZToRowUnlocalized(tr, tz_data, dates) end local cd = tr:tag('td') :wikitext(util_time.countdown(row.UTC)) util_toggle.oflCellClasses(cd, self.toggles, 'me') end

function p:printTbdCell(tr, colspan, toggleState) local td = tr:tag('td') td:attr('colspan', colspan) :addClass('sfs-tbd') :wikitext('TBD') util_toggle.oflCellClasses(td, self.toggles, toggleState) end

function p:getTZData(row) util_time.addTimezonesToRowFromUTC(row) local tbl = {} for _, v in ipairs(self.timezones) do		local date = row[v]:match('(%d%d%d%d%-%d%d%-%d%d)') local time = row[v]:match('(%d%d:%d%d)') tbl[v] = { date = date, time = time } end return tbl end

function p:addTZToRow(tr, data) for _, v in ipairs(self.timezones) do		local td = tr:tag('td') :wikitext(data[v].time) util_toggle.oflCellClasses(td, self.toggles, 'me') end end

function h.getAbsoluteDates(str) local utc_time = util_time.strToTime(str) local utc_midnight = mw.clone(utc_time) utc_midnight.hour = 0 utc_midnight.min = 0 utc_midnight.sec = 0 local dif = os.difftime(os.time(utc_time), os.time(utc_midnight)) local dates = {} if dif >= 43200 then -- 12 * 60 * 60 local today = date(utc_time) dates[1] = today:fmt('%Y-%m-%d') local tomorrow = today:adddays(1) dates[2] = tomorrow:fmt('%Y-%m-%d') else local today = date(utc_time) dates[2] = today:fmt('%Y-%m-%d') local yesterday = today:adddays(-1) local y, m, d = yesterday:getdate dates[1] = yesterday:fmt('%Y-%m-%d') end return dates end

function p:addAbsDates(tr, dates) for i, v in ipairs(dates) do		local td = tr:tag('td') :addClass('sfs-date' .. i)			:wikitext(v) util_toggle.oflCellClasses(td, self.toggles, 'general') end end

function p:addTZToRowUnlocalized(tr, data, dates) for _, v in ipairs(self.timezones) do		local td = tr:tag('td') :wikitext(data[v].time) :attr('data-date', data[v].date) util_toggle.oflCellClasses(td, self.toggles, 'general') if data[v].date == dates[1] then td:addClass('sfs-date1') elseif data[v].date == dates[2] then td:addClass('sfs-date2') end end end

return p