Módulo:Conversor de data
Saltar para a navegação
Saltar para a pesquisa
A documentação para este módulo pode ser criada na página Módulo:Conversor de data/doc
local p = {} local patterns = {"(%d+)-(%d+)-(%d+)", "(%d+)/(%d+)/(%d+)", "(%d+)%.(%d+)%.(%d+)"} local month_names = {"janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro"} function p.main( frame ) local date = frame.args[1] local day, month, year = 0, 0, 0 for key, value in pairs(patterns) do local day, month, year = string.match(date, value) year = tonumber(year) day = tonumber(day) month = tonumber(month) -- Inverte dia pelo ano, caso o formato da data for xxxx/xx/xx if (day and day > 100) then day, year = year, day end -- Soma dois mil caso a data inserida for de dois dígitos if (year and year < 100) then year = year + 2000 end -- Inverte dia pelo mes, caso o formato da data mês/dia/ano if (month and (month > 12 and month < 32)) then day, month = month, day end -- Algumas poucas páginas tinham erro de índice inexistente para o mês if (month and (month > 12 or month < 1)) then month = nil end if (day and month and year) ~= nil then return day .. " de " .. month_names[month] .. " de " .. year end end return date end return p