Sari la conținut

Modul:BirthDateAndAge

De la Wikipedia, enciclopedia liberă

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

localp={}
localgetArgs=require('Modul:Arguments').getArgs
localwikidata=require('Modul:Wikidata')
localplural=require('Modul:Plural').get_plural
localGregorianDate=require('Modul:GregorianDate')

localcomputeYearsPastBetween=function(inMomentDate,inReferenceDate)
localmomentDate=GregorianDate.julianToGregorian(inMomentDate)
localreferenceDate=GregorianDate.julianToGregorian(inReferenceDate)
localyearsDiff=tonumber(momentDate.year)-tonumber(referenceDate.year)
iftonumber(momentDate.month)<tonumber(referenceDate.month)or(tonumber(momentDate.month)==tonumber(referenceDate.month)andtonumber(momentDate.day)<tonumber(referenceDate.day))then
yearsDiff=yearsDiff-1
end
returnyearsDiff
end

localcomputeYearsPastSince=function(referenceDate)
returncomputeYearsPastBetween(os.date("*t"),referenceDate)
end

p._getBdaByWikidata=function(args)
locallink=false
ifargs['link']andmw.text.trim(args['link'])~=''then
link=true
end
localbirthDates=wikidata.findDateValues('P569',nil)
localdeathDates=wikidata.findDateValues('P570',nil)
ifbirthDatesandbirthDates[1]andbirthDates[1].claimandbirthDates[1].claim.type=='statement'andbirthDates[1].claim.mainsnak.snaktype=='value'then
localout=GregorianDate.displayDualDateIfInInterval(birthDates[1],link)
ifnotdeathDatesornotdeathDates[1]or(deathDates[1].claimanddeathDates[1].claim.mainsnak.snaktype=='novalue')then
age=computeYearsPastSince(birthDates[1])
ifage<120andbirthDates[1].precision>7then
out=out..' ('..plural{args={age,'an','ani','de ani'}}..')'
else
out=out..'[[Categorie:Decese cu dată necunoscută]]'
end
end
ifbirthDates[1].claimthen
out=out..wikidata.outputReferences(birthDates[1].claim)
end
returnout
end
return''
end

p.getBdaByWikidata=function(frame)
localargs=getArgs(frame)
returnp._getBdaByWikidata(args)
end

p.getBda=function(frame)
localargs=getArgs(frame)
locallink=false
ifargs['link']andmw.text.trim(args['link'])~=''then
link=true
end
locald={}
ifargs[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']orargs['calendar']or'gregorian')
ifargs[2]thend.precision=10end
ifargs[3]thend.precision=11end
out=GregorianDate.displayDualDateIfInInterval(d,link)
ifd.precision>7then
out=out..' ('..plural{args={computeYearsPastSince(d),'an','ani','de ani'}}..')'
end
returnout
else
returnp.getBdaByWikidata(frame)
end
end

p._getDdaByWikidata=function(args)
localbirthDates=wikidata.findDateValues('P569',nil)
localdeathDates=wikidata.findDateValues('P570',nil)
locallink=false
ifargs['link']andmw.text.trim(args['link'])~=''then
link=true
end
ifdeathDatesanddeathDates[1]and(notdeathDates[1].claimordeathDates[1].claim.mainsnak.snaktype=='value')then
localout=''
out=out..GregorianDate.displayDualDateIfInInterval(deathDates[1],link)
ifbirthDatesandbirthDates[1]and(notbirthDates[1].claimorbirthDates[1].claim.mainsnak.snaktype=='value')then
ifdeathDates[1].precision>7andbirthDates[1].precision>7then
out=out..' ('..plural{args={computeYearsPastBetween(deathDates[1],birthDates[1]),'an','ani','de ani'}}..')'
end
end
ifdeathDates[1].claimthen
out=out..wikidata.outputReferences(deathDates[1].claim)
end
returnout
end
return''
end

p.getDdaByWikidata=function(frame)
localargs=getArgs(frame)
returnp._getDdaByWikidata(args)
end
p.getDda=function(frame)
localargs=getArgs(frame)
locallink=false
ifargs['link']andmw.text.trim(args['link'])~=''then
link=true
end
ifargs[1]then
locald={}
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')
ifargs[2]thend.precision=10end
ifargs[3]thend.precision=11end
localb={}
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')
ifargs[5]thenb.precision=10end
ifargs[6]thenb.precision=11end
returnGregorianDate.displayDualDateIfInInterval(d,link)..' ('..plural{args={computeYearsPastBetween(d,b),'an','ani','de ani'}}..')'
else
returnp.getDdaByWikidata(frame)
end
end

returnp