Модуль:StringDates2Need

Материал из Викиновостей, свободного источника новостей
Документация
--[[
------------------------------------------
--              GetArticleDate
-- Модуль для преобразования строковой даты дд месяц год в нужную.
------------------------------------------
--]]

local StringDates2Need = {}
local SerializeTable = require("Module:SerializeTable")

function StringDates2Need.YMD(frame) --Year, month, day
	local s = frame.args[1]
	
	if (s == nil or s == '') then return 0 end
	
	local dd = ""
	local mm = ""
	local yy = ""
	
	for i=1, #s do 
		local c = s:sub(i,i)
		if c == ' ' then break 
		else dd = dd .. c end
	end
	if #dd < 2 then dd = "0" .. dd end
	
	if string.find(s, "января") then mm = "01"
	elseif string.find(s, "февраля") then mm = "02" 
	elseif string.find(s, "марта") then mm = "03" 
	elseif string.find(s, "апреля") then mm = "04" 
	elseif string.find(s, "мая") then mm = "05" 
	elseif string.find(s, "июня") then mm = "06" 
	elseif string.find(s, "июля") then mm = "07" 
	elseif string.find(s, "августа") then mm = "08" 
	elseif string.find(s, "сентября") then mm = "09" 
	elseif string.find(s, "октября") then mm = "10" 
	elseif string.find(s, "ноября") then mm = "11" 
	elseif string.find(s, "декабря") then mm = "12" 
	end
	
	for i=#s-1, 1, -1 do
		local c = s:sub(i,i)
		if c == ' ' then break
		else yy = c .. yy end
	end
	if #yy == 1 then yy = "000" .. yy
	elseif #yy == 2 then yy = "00" .. yy
	elseif #yy == 3 then yy = "0" .. yy
	end
	
	local answer = yy .. " " .. mm .. " " .. dd
	return answer
	
end


return StringDates2Need