Difference between revisions of "Module:Birthday"

From Story Lists
Jump to navigation Jump to search
Line 14: Line 14:


if(mw.ustring.find(date, "January")) then
if(mw.ustring.find(date, "January")) then
month = 1
month = "1"
day = mw.ustring.gsub(date, "January ", "")  
day = mw.ustring.gsub(date, "January ", "")  
elseif(mw.ustring.find(date, "February")) then
elseif(mw.ustring.find(date, "February")) then
month = 2
month = "2"
day = mw.ustring.gsub(date, "February ", "")  
day = mw.ustring.gsub(date, "February ", "")  
elseif(mw.ustring.find(date, "March")) then
elseif(mw.ustring.find(date, "March")) then
month = 3
month = "3"
day = mw.ustring.gsub(date, "March ", "")  
day = mw.ustring.gsub(date, "March ", "")  
elseif(mw.ustring.find(date, "April")) then
elseif(mw.ustring.find(date, "April")) then
month = 4
month = "4"
day = mw.ustring.gsub(date, "April ", "")  
day = mw.ustring.gsub(date, "April ", "")  
elseif(mw.ustring.find(date, "May")) then
elseif(mw.ustring.find(date, "May")) then
month = 5
month = "5"
day = mw.ustring.gsub(date, "May ", "")  
day = mw.ustring.gsub(date, "May ", "")  
elseif(mw.ustring.find(date, "June")) then
elseif(mw.ustring.find(date, "June")) then
month = 6
month = "6"
day = mw.ustring.gsub(date, "June ", "")  
day = mw.ustring.gsub(date, "June ", "")  
elseif(mw.ustring.find(date, "July")) then
elseif(mw.ustring.find(date, "July")) then
month = 7
month = "7"
day = mw.ustring.gsub(date, "July ", "")  
day = mw.ustring.gsub(date, "July ", "")  
elseif(mw.ustring.find(date, "August")) then
elseif(mw.ustring.find(date, "August")) then
month = 8
month = "8"
day = mw.ustring.gsub(date, "August ", "")  
day = mw.ustring.gsub(date, "August ", "")  
elseif(mw.ustring.find(date, "September")) then
elseif(mw.ustring.find(date, "September")) then
month = 9
month = "9"
day = mw.ustring.gsub(date, "September ", "")  
day = mw.ustring.gsub(date, "September ", "")  
elseif(mw.ustring.find(date, "October")) then
elseif(mw.ustring.find(date, "October")) then
month = A
month = "A"
day = mw.ustring.gsub(date, "October ", "")  
day = mw.ustring.gsub(date, "October ", "")  
elseif(mw.ustring.find(date, "November")) then
elseif(mw.ustring.find(date, "November")) then
month = B
month = "B"
day = mw.ustring.gsub(date, "November ", "")  
day = mw.ustring.gsub(date, "November ", "")  
elseif(mw.ustring.find(date, "December")) then
elseif(mw.ustring.find(date, "December")) then
month = C
month = "C"
day = mw.ustring.gsub(date, "December ", "")  
day = mw.ustring.gsub(date, "December ", "")  
end
end

Revision as of 13:42, 9 May 2021

Documentation for this module may be created at Module:Birthday/doc

local p = {}

function p.main(frame)
	local titleObject = mw.title.getCurrentTitle()
	local titleText = titleObject.fullText

	-- "date" variable is a value like "December 9", taken from the page title
	local date = mw.ustring.gsub(titleText, "List of characters born on ", "") 

	-- "month" and "day" variables are used to sort the pages in "Category:Lists of characters by birthday"
	-- "month" is the month number (1 = January, 2 = February, etc.) except, for sorting purposes, the last three months are letters (A = September, B = October, C = December)
	local month = ""
	local day = ""

	if(mw.ustring.find(date, "January")) then
		month = "1"
		day = mw.ustring.gsub(date, "January ", "") 
	elseif(mw.ustring.find(date, "February")) then
		month = "2"
		day = mw.ustring.gsub(date, "February ", "") 
	elseif(mw.ustring.find(date, "March")) then
		month = "3"
		day = mw.ustring.gsub(date, "March ", "") 
	elseif(mw.ustring.find(date, "April")) then
		month = "4"
		day = mw.ustring.gsub(date, "April ", "") 
	elseif(mw.ustring.find(date, "May")) then
		month = "5"
		day = mw.ustring.gsub(date, "May ", "") 
	elseif(mw.ustring.find(date, "June")) then
		month = "6"
		day = mw.ustring.gsub(date, "June ", "") 
	elseif(mw.ustring.find(date, "July")) then
		month = "7"
		day = mw.ustring.gsub(date, "July ", "") 
	elseif(mw.ustring.find(date, "August")) then
		month = "8"
		day = mw.ustring.gsub(date, "August ", "") 
	elseif(mw.ustring.find(date, "September")) then
		month = "9"
		day = mw.ustring.gsub(date, "September ", "") 
	elseif(mw.ustring.find(date, "October")) then
		month = "A"
		day = mw.ustring.gsub(date, "October ", "") 
	elseif(mw.ustring.find(date, "November")) then
		month = "B"
		day = mw.ustring.gsub(date, "November ", "") 
	elseif(mw.ustring.find(date, "December")) then
		month = "C"
		day = mw.ustring.gsub(date, "December ", "") 
	end

	local result = "This is a list of characters born on " .. date .. "."

	local result  = result .. "[[Category:Lists]]"
	local result  = result .. "[[Category:Lists of characters by birthday|" .. month .. "-" .. day .. "]]"

	return result
end

return p