Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:AgeTemplate: Difference between revisions

From ProleWiki, the proletarian encyclopedia
m (Further debugging)
m (Added function to calculate leap years)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local function isLeapYear(Year)
if Year%400 == 0 then
return true
end
if Year%4 == 0 and Year%100 ~= 0 then
return true
end
return false
end


function p.age( frame )
function p.age( frame )
Line 8: Line 18:
local arg3 = pframe.args[3]
local arg3 = pframe.args[3]
local initialDate = ""
local endDate = ""
if arg1 == "1" or arg1 == "2" or arg1 == "3" then
if arg1 == "1" or arg1 == "2" or arg1 == "3" then
local initialDate = pframe.args[2]
initialDate = arg2
endDate = arg3
else
else
local initialDate = pframe.args[1]
initialDate = arg1
endDate = arg2
end
end
return "initialDate: " .. pframe.args[1]
local year,month,day = string.match(initialDate, '(%d+)-(%d+)-(%d+)')
end
end
-- local year,month,day = string.match(initialDate, '(%d+)-(%d+)-(%d+)')
-- return "Year: " .. year .. ", Month: " .. month .. ", Day: " .. day
-- end
return p
return p

Latest revision as of 22:27, 3 September 2022

local p = {}

local function isLeapYear(Year)
	if Year%400 == 0 then
		return true
	end
	if Year%4 == 0 and Year%100 ~= 0 then
		return true
	end
	return false
end

function p.age( frame )
	local pframe = frame:getParent()
	
	local arg1 = pframe.args[1]
	local arg2 = pframe.args[2]
	local arg3 = pframe.args[3]
	
	local initialDate = ""
	local endDate = ""
	if arg1 == "1" or arg1 == "2" or arg1 == "3" then
		initialDate = arg2
		endDate = arg3
		else
			initialDate = arg1
			endDate = arg2
	end
	local year,month,day = string.match(initialDate, '(%d+)-(%d+)-(%d+)')
end
return p