Module:Sandbox/Swpb/sandbox

local TableTools = require('Module:TableTools') local p = {}

function p.main(frame) no_of_entries = TableTools.size(frame.args)/2 state, day, evs, year = {}, {}, {}, {} i = 1 while ( i <= no_of_entries ) do		state[i] = frame.args[2*i-1] day[i] = frame.args[2*i] --		evs[i] = frame:expandTemplate{ title = 'USHRseats', args = { state[i], day[i] } } i = i + 1 end

--	Match up leave entries with start entries start_state, start_date, start_year, end_date, end_year = {}, {}, {}, {}, {} i = 1 j = 1 while ( i <= no_of_entries ) do		if not ( mw.ustring.match(state[i],'-') ) then start_state[j] = state[i] start_date[j] = day[i] start_year[j] = tonumber(mw.ustring.match( day[i], "%d%d%d%d" )) j = j + 1 else leave_state = mw.ustring.match(state[i],'%a%a') for k, state_name in ipairs(start_state) do				if ( leave_state == state_name and not end_date[k] ) then leave_state_index = k					break end end end_date[leave_state_index] = day[i] end_year[leave_state_index] = tonumber(mw.ustring.match( day[i], "%d%d%d%d" )) end i = i + 1 end -- Pre 2010 census i = 1 tot = 0 census_year = 2010 while ( i <= TableTools.size(start_state) ) do		if ( start_year[i] <= census_year ) then end i = i + 1 end

return start_state[12] .. " " .. start_date[12] .. " " .. start_year[12] .. " " .. end_date[10] end

return p