Module:Age

From Absit Omen Lexicon
Revision as of 02:10, 20 June 2021 by Cody (talk | contribs) ((by SublimeText.Mediawiker))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

local Date = require("Module:Date")._Date

function p.age(frame)

	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)

	local startDate = Date(args[1], args[2], args[3])

	local endDate

	if args[4] == nil then
		endDate = Date('currentdate')
	else
		endDate = Date(args[4], args[5] or 'partial', args[6] or 'partial')
	end

	if endDate == nil then
		return '(age calculation issue)'
	end

	local dateDiff = endDate:subtract(startDate, 'wantrange')
	local age
	if dateDiff then
		age = type(dateDiff:age('y', {['range'] = true})) == 'table' and 
		table.concat(dateDiff:age('y', {['range'] = true}), '-') or dateDiff:age('y')

		if age == nil then
			age = '(age calculation issue)'
		end
	end

	return age

end

return p