Dokumentasie vir hierdie module kan geskep word by: Module:Eeuboks/doc

local p = {};     --All Lua modules on Wikipedia must begin by defining a variable 
                    --that will hold their externally accessible functions.
                    --Such variables can have whatever name you want and may 
                    --also contain various data as well as functions.
p.kry_millennium_van_eeu = function(frame)     --Add a function to "p".  
                                        --Such functions are callable in Wikipedia
                                        --via the #invoke command.
                                        --"frame" will contain the data that Wikipedia
                                        --sends this function when it runs. 
                                 -- 'millenniumlys' is a name of your choice. The same name needs to be referred to when the module is used.
    
    local eeu = tonumber(frame.args[1])  -- To access arguments passed to a module, use `frame.args`
							    -- `frame.args[1]` refers to the first unnamed parameter given to the module
	local mill_num = math.floor((math.abs(eeu) - 1) / 10) + 1 -- abs value (negative is removed)
	
	if mill_num == 0 and eeu < 0 then
		mill_num = -1
	end
		
	local mill_str = "[[" .. tostring(mill_num) .. getOrdinalSuffix(mill_num) .. " millennium]]"
	
	if eeu < 0 then
		mill_str = "[[" .. tostring(mill_num) .. getOrdinalSuffix(mill_num) .. " millennium v.C.]]"
	end
	
	return mill_str
	
end -- end of function

p.kry_eeu_reeks = function(frame)
	local eeu = tonumber(frame.args[1])  -- To access arguments passed to a module, use `frame.args`
							    -- `frame.args[1]` refers to the first unnamed parameter given to the module
	
	local output1 = getEeuStr(subtractEeu(eeu))
	local output2 = getEeuStr(eeu)
	local output3 = getEeuStr(addEeu(eeu))
	
	return output1 .. output2 .. output3  -- `..` concatenates strings.

end -- end of function

p.kry_dekade_reeks = function(frame)
	local eeu = tonumber(frame.args[1])  -- To access arguments passed to a module, use `frame.args`
							    -- `frame.args[1]` refers to the first unnamed parameter given to the module
	local output = ""
	
	if eeu > 0 then
		local century_start = (eeu - 1) * 100 -- e.g. the year 2000
	    local century_end = century_start + 90 -- subtracting 10 because it is the start of the last dek in the eeu
	    
	    local i = 0
	    for decade = century_start, century_end, 10 do
	    	i = i + 1
	        output = output .. "* [[" .. tostring(decade) .. "'s]]\n"
	        if i == 5 then
	        	output = output .. "\n" -- forseer 5 op 'n lyn
	        end
	    end
		
		return output
		
	elseif eeu < 0 then
		local century_start = (eeu * 100) + 100 -- e.g. the year 2000 BC
	    local century_end = (eeu * 100) + 10
	    
	    local i = 0
	    for decade = century_end, century_start, 10 do
	    	i = i + 1
	    	if decade == 0 then
	    		output = output .. "* [[" .. tostring(decade) .. "'s v.C.]]\n" -- edge case
	    	else
	        	output = output .. "* [[" .. tostring(decade * -1) .. "'s v.C.]]\n"
	        end
	        if i % 2 == 0 then
	        	output = output .. "\n" -- forseer 2 op 'n lyn -- TODO fix multiple line breaks mysteriously getting inserted after the decade list
	        end
	    end
		
		return output
	else 
		return "Fout geen 0de eeu bestaan"
	end

end -- end of function

function subtractEeu(num)
	if num == 1 then
		return -1
	else
		return num - 1
	end
end

function addEeu(num)
	if num == -1 then
		return 1
	else
		return num + 1
	end
end

function getEeuStr(num)
	if num > 0 then
		return "* [[" .. tostring(num) .. getOrdinalSuffix(num) .. " eeu]]\n"
	elseif num == 0 then
		print("ERROR eeu 0 does not exist")
	elseif num < 0 then
		return "* [[" .. tostring(num * -1) .. getOrdinalSuffix(num * -1) .. " eeu v.C.]]\n"
	end
end

p.kry_sterf_kat_str = function(frame)
	local num = tonumber(frame.args[1])

	if num > 0 then
		return "[[:Kategorie:Sterftes_in_die_" .. tostring(num) .. getOrdinalSuffix(num) .. "_eeu|Sterftes]]"
	elseif num == 0 then
		print("ERROR eeu 0 does not exist")
	elseif num < 0 then
		return "[[:Kategorie:Sterftes_in_die_" .. tostring(num * -1) .. getOrdinalSuffix(num * -1) .. "_eeu_v.C.|Sterftes]]"
	end
end

p.kry_geboortes_kat_str = function(frame)
	local num = tonumber(frame.args[1])

	if num > 0 then
		return "[[:Kategorie:Geboortes_in_die_" .. tostring(num) .. getOrdinalSuffix(num) .. "_eeu|Geboortes]]"
	elseif num == 0 then
		print("ERROR eeu 0 does not exist")
	elseif num < 0 then
		return "[[:Kategorie:Geboortes_in_die_" .. tostring(num * -1) .. getOrdinalSuffix(num * -1) .. "_eeu_v.C.|Geboortes]]"
	end
end


function getOrdinalSuffix(num)

	local suffix = "ste"
	if num > 1 and num < 20 and num ~= 8 then
		suffix = "de"
	end
	
	return suffix
end

return p    --All modules end by returning the variable containing their functions to Wikipedia.