Module:Sandbox/Angr pukhlya/2/sandbox

This is an old revision of this page, as edited by Angr pukhlya (talk | contribs) at 19:07, 29 November 2018. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

p.o = function( frame )
	-- Unpacking date in not iso-format
	local date = frame.args.date
	local year, day = string.match(date, "%D*(%d*)%D*(%d*)%D*")
	if tonumber(day) > 31 then
		day, year = year, day
	end
	months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
	local k = nil
	local month = nil
	for i = 1, #months do
		k = string.find(date, months[i])
		if k == nil then
			k = string.find(date, string.lower(string.sub(months[i], 1, 1)) .. string.sub(months[i], 2))
		end
		if k == nil then
			k = string.find(date, string.lower(string.sub(months[i], 1, 1)) .. string.sub(months[i], 2, 3))
		end
		if k == nil then
			k = string.find(date, string.sub(months[i], 1, 1) .. string.sub(months[i], 2, 3))
		end
		if k ~= nil then
			month = months[i]
		end
	end
	if month == nil then
		local day, month, year = string.match(date, "(%d+)[-, /](%d+)[-, /](%d+)")
		local a, b, c = day, month, year
		if tonumber(a) > 31 then
			year = a
		elseif tonumber(b) > 31 then
			year = b
		elseif tonumber(c) > 31 then
			year = c
		end
		if tonumber(a) > 12 and year ~= nil and year ~= a then
			day = a
		elseif tonumber(b) > 12 and year ~= nil and year ~= b then
			day = b
		elseif tonumber(c) > 12 and year ~= nil and year ~= c then
			day = c
		end
		if (year == a and day == b) or (year == b and day == a) then
			month = c
		elseif (year == b and day == c) or (year == c and day == b) then
			month = a
		elseif (year == a and day == c) or (year == c and day == a) then
			month = b
		else
			day, month, year = a, b, c
		end
	end
	return "Day = " .. day .. "<br>" .. 
	       "Month = " .. month .. "<br>" ..
	       "Year = " .. year
end
return p