Module:British parliamentary session

Revision as of 20:51, 15 July 2021 by Zoran (talk | contribs) (Pywikibot 6.4.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
local p = {}

function p.citation( frame )
	
	local inputDate
	if frame == mw.getCurrentFrame() then
		inputDate = frame:getParent().args[ 1 ]
		local frameArgsDate = frame.args[ 1 ]
		if frameArgsDate then
			inputDate = frameArgsDate
		end
	else
		inputDate = frame
	end
	
	inputDate = tonumber ( inputDate )
	
	if inputDate >= os.time{day=1, month=1, year=1963} then
		return os.date("%Y",inputDate)
	else
		local data = mw.loadData( 'Module:British parliamentary session/data' )
		for _, t in ipairs( data ) do
			if inputDate >= t.sDate and inputDate <= t.eDate then
				return t.citation
			end
		end
    end
end

function p.sortorder( frame )
	
	local inputDate
	if frame == mw.getCurrentFrame() then
		inputDate = frame:getParent().args[ 1 ]
		local frameArgsDate = frame.args[ 1 ]
		if frameArgsDate then
			inputDate = frameArgsDate
		end
	else
		inputDate = frame
	end
	
	inputDate = tonumber ( inputDate )
	
	if inputDate >= os.time{day=1, month=1, year=1963} then
		return os.date("%Y",inputDate)
	else
		local data = mw.loadData( 'Module:British parliamentary session/data' )
		for _, t in ipairs( data ) do
			if inputDate >= t.sDate and inputDate <= t.eDate then
				return t.sortorder
			end
		end
    end
end

function p.archive( frame )
	
	local inputDate
	if frame == mw.getCurrentFrame() then
		inputDate = frame:getParent().args[ 1 ]
		local frameArgsDate = frame.args[ 1 ]
		if frameArgsDate then
			inputDate = frameArgsDate
		end
	else
		inputDate = frame
	end
	
	inputDate = tonumber ( inputDate )
	
	if inputDate >= os.time{day=1, month=1, year=1963} then
		return ""
	else
		local data = mw.loadData( 'Module:British parliamentary session/data' )
		for _, t in ipairs( data ) do
			if inputDate >= t.sDate and inputDate <= t.eDate then
				return t.archive
			end
		end
    end
end

return p