Module:GetBirthDate
Documentation for this module may be created at Module:GetBirthDate/doc
local p = {}
local PBD = require('Module:PBD')
local function splitDate(date)
local day, month, year = nil, nil, nil
if date then
day, month, year = string.match(date, '(%d+)%s+(%a+)%s+(%d+)')
if not year then
month, day = string.match(date, '(%a+)%s+(%d+)')
if not day then
day, month = string.match(date, '(%d+)%s+(%a+)')
end
end
if not month and not day then
year = string.match(date, '(%d+)')
end
end
if day then day = tonumber(day) end
if year then year = tonumber(year) end
return day, month, year
end
local function monthToNumber(month)
local monthNames = {
["January"] = 1, ["February"] = 2, ["March"] = 3,
["April"] = 4, ["May"] = 5, ["June"] = 6,
["July"] = 7, ["August"] = 8, ["September"] = 9,
["October"] = 10, ["November"] = 11, ["December"] = 12
}
return monthNames[month]
end
function p.property(frame)
local propertyId = frame.args[1]
local part = frame.args[2]
local format = frame.args[3] or 'number'
local date = PBD.property(frame, propertyId)
local day, month, year = splitDate(date)
local result = ''
if part == 'day' and day then
result = day
elseif part == 'month' and month then
if format == 'name' then
result = month
else
result = monthToNumber(month)
end
elseif part == 'year' and year then
result = year
end
return result
end
return p