Module:Age

From Absit Omen Lexicon
Revision as of 02:02, 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(args)


	processArgs(args)

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

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

	local dateDiff endDate:subtract(startDate, 'wantrange')

	if dateDiff then
		local 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