Editing Module:Deathage

From Catpedia
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
local p = {}
local p = {}
function p.formatDate(frame)
function p.formatDate(frame)
     local day = tonumber(frame.args[4]) or 1
     local day = tonumber(frame.args[4]) or 1
Line 7: Line 6:
     return mw.getContentLanguage():formatDate('j F Y', string.format('%d-%d-%d', year, month, day))
     return mw.getContentLanguage():formatDate('j F Y', string.format('%d-%d-%d', year, month, day))
end
end
function p.calculateAge(frame)
function p.calculateAge(frame)
     local birthDay = tonumber(frame.args[1]) or 1
     local day = tonumber(frame.args[1]) or 1
     local birthMonth = tonumber(frame.args[2]) or 1
     local month = tonumber(frame.args[2]) or 1
     local birthYear = tonumber(frame.args[3]) or 1970
     local year = tonumber(frame.args[3]) or 1970
     local deathDay = tonumber(frame.args[4]) or 1
     local currentDay = tonumber(mw.getCurrentFrame():callParserFunction('#time', 'j'))
     local deathMonth = tonumber(frame.args[5]) or 1
     local currentMonth = tonumber(mw.getCurrentFrame():callParserFunction('#time', 'n'))
     local deathYear = tonumber(frame.args[6]) or 1970
     local currentYear = tonumber(mw.getCurrentFrame():callParserFunction('#time', 'Y'))
 
     local age = currentYear - year
     local age = deathYear - birthYear
     if (currentMonth < month) or (currentMonth == month and currentDay < day) then
     if (deathMonth < birthMonth) or (deathMonth == birthMonth and deathDay < birthDay) then
         age = age - 1
         age = age - 1
     end
     end
     return age
     return age
end
end
function p.displayDateWithAge(frame)
function p.displayDateWithAge(frame)
     local date = p.formatDate(frame)
     local date = p.formatDate(frame)
Line 29: Line 24:
     return string.format('%s (aged %d)', date, age)
     return string.format('%s (aged %d)', date, age)
end
end
return p
return p
Please note that all contributions to Catpedia are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see Catpedia:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)

Template used on this page: