For faster navigation, this Iframe is preloading the Wikiwand page for Modul:BirthDateAndAge.

Modul:BirthDateAndAge

Documentația acestui modul poate fi creată la Modul:BirthDateAndAge/doc

local p = {}
local getArgs = require('Modul:Arguments').getArgs
local wikidata = require('Modul:Wikidata')
local plural = require('Modul:Plural').get_plural
local GregorianDate = require('Modul:GregorianDate')

local computeYearsPastBetween = function(inMomentDate, inReferenceDate)
	local momentDate = GregorianDate.julianToGregorian(inMomentDate)
	local referenceDate = GregorianDate.julianToGregorian(inReferenceDate)
	local yearsDiff = tonumber(momentDate.year) - tonumber(referenceDate.year)
	if tonumber(momentDate.month) < tonumber(referenceDate.month) or (tonumber(momentDate.month) == tonumber(referenceDate.month) and tonumber(momentDate.day) < tonumber(referenceDate.day)) then
		yearsDiff = yearsDiff - 1
	end
	return yearsDiff
end

local computeYearsPastSince = function(referenceDate) 
	return computeYearsPastBetween(os.date("*t"), referenceDate)
end

p._getBdaByWikidata = function(args) 
	local link = false
	if args['link'] and mw.text.trim(args['link']) ~= '' then
		link = true
	end
	local birthDates = wikidata.findDateValues('P569', args.q)
	local deathDates = wikidata.findDateValues('P570', args.q)
	if birthDates and birthDates[1] and birthDates[1].claim and birthDates[1].claim.type == 'statement' and birthDates[1].claim.mainsnak.snaktype == 'value' then
		local out = GregorianDate.displayDualDateIfInInterval(birthDates[1], link)
		if not deathDates or not deathDates[1] or (deathDates[1].claim and deathDates[1].claim.mainsnak.snaktype == 'novalue') then
			age = computeYearsPastSince(birthDates[1])
			if age < 120 and birthDates[1].precision > 7 then
				out = out .. ' (' .. plural{args={age, 'an', 'ani', 'de ani')) .. ')'
			else
				out = out .. '[[Categorie:Decese cu dată necunoscută]]'
			end
		end
		if birthDates[1].claim then
			out = out .. wikidata.outputReferences(birthDates[1].claim)
		end
		return out
	end
	return ''
end

p.getBdaByWikidata = function(frame) 
	local args = getArgs(frame)
	return p._getBdaByWikidata(args)
end

p.getBda = function(frame) 
	local args = getArgs(frame)
	local link = false
	if args['link'] and mw.text.trim(args['link']) ~= '' then
		link = true
	end
	local d = {}
	if args[1] then
		d.year = tonumber(args[1])
		d.month = tonumber(args[2] or '1')
		d.day = tonumber(args[3] or '1')
		d.precision = 9
		d.calendar = mw.ustring.lower(args['calendar_birth'] or args['calendar'] or 'gregorian')
		if args[2] then d.precision = 10 end
		if args[3] then d.precision = 11 end
		out = GregorianDate.displayDualDateIfInInterval(d, link)
		if d.precision > 7 then
			out = out .. ' (' .. plural{args={computeYearsPastSince(d), 'an', 'ani', 'de ani')) .. ')'
		end
		return  out
	else
		return p.getBdaByWikidata(frame)
	end
end

p._getDdaByWikidata = function(args) 
	local birthDates = wikidata.findDateValues('P569', nil)
	local deathDates = wikidata.findDateValues('P570', nil)
	local link = false
	if args['link'] and mw.text.trim(args['link']) ~= '' then
		link = true
	end
	if deathDates and deathDates[1] and (not deathDates[1].claim or deathDates[1].claim.mainsnak.snaktype == 'value') then
		local out = ''
		out = out .. GregorianDate.displayDualDateIfInInterval(deathDates[1], link)
		if birthDates and birthDates[1] and (not birthDates[1].claim or birthDates[1].claim.mainsnak.snaktype == 'value') then
			if deathDates[1].precision > 7 and birthDates[1].precision > 7 then
				out = out .. ' (' .. plural{args={computeYearsPastBetween(deathDates[1], birthDates[1]), 'an', 'ani', 'de ani')) .. ')'
			end
		end
		if deathDates[1].claim then
			out = out .. wikidata.outputReferences(deathDates[1].claim)
		end
		return out
	end
	return ''
end

p.getDdaByWikidata = function(frame) 
	local args = getArgs(frame)
	return p._getDdaByWikidata(args)
end
p.getDda = function(frame)
	local args = getArgs(frame)
	local link = false
	if args['link'] and mw.text.trim(args['link']) ~= '' then
		link = true
	end
	if args[1] then
		local d = {}
		d.year = tonumber(args[1])
		d.month = tonumber(args[2] or '1')
		d.day = tonumber(args[3] or '1')
		d.precision = 9
		d.calendar = mw.ustring.lower(args['calendar_death'] or 'gregorian')
		if args[2] then d.precision = 10 end
		if args[3] then d.precision = 11 end
		local b = {}
		b.year = tonumber(args[4])
		b.month = tonumber(args[5] or '1')
		b.day = tonumber(args[6] or '1')
		b.precision = 9
		b.calendar = mw.ustring.lower(args['calendar_birth'] or 'gregorian')
		if args[5] then b.precision = 10 end
		if args[6] then b.precision = 11 end
		return GregorianDate.displayDualDateIfInInterval(d, link) .. ' (' ..  plural{args={computeYearsPastBetween(d, b), 'an', 'ani', 'de ani')) .. ')'
	else
		return p.getDdaByWikidata(frame)
	end
end

return p
{{bottomLinkPreText}} {{bottomLinkText}}
Modul:BirthDateAndAge
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?