Module:Wiktionary:Word of the day/Status

Hello, you have come here looking for the meaning of the word Module:Wiktionary:Word of the day/Status. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:Wiktionary:Word of the day/Status, but we will also tell you about its etymology, its characteristics and you will know how to say Module:Wiktionary:Word of the day/Status in singular and plural. Everything you need to know about the word Module:Wiktionary:Word of the day/Status you have here. The definition of the word Module:Wiktionary:Word of the day/Status will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:Wiktionary:Word of the day/Status, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local export = {}

local function trim(list)
	local trimmed = {}
	for line in pairs(list) do
		if list ~= nil then
			table.insert(trimmed, list)
		end
	end
	return trimmed
end

local function listify(list, delim)
	local output = nil
	local trimmed = trim(list)
	for line in pairs(trimmed) do
		if line == 1 then
			output = trimmed
		elseif line == #trimmed then
			if line == 2 then
				output = output .. " and " .. trimmed
			else
				output = output .. delim .. "and " .. trimmed
			end
		else
			output = output .. delim .. trimmed
		end
	end
	return output
end

local function rangify(list, delim)
	local trimmed = trim(list)
	local ranges = {}
	local current_range_start = nil
	local current_range_end = nil
	for index, entry in ipairs(trimmed) do
		if current_range_end ~= entry - 1 then
			if current_range_start ~= nil then
				if current_range_start == current_range_end then
					table.insert(ranges, ""..current_range_start)
				else
					table.insert(ranges, current_range_start..delim..current_range_end)
				end
			end
			current_range_start = entry
		end
		current_range_end = entry
	end
	if current_range_start ~= nil then
		if current_range_start == current_range_end then
			table.insert(ranges, ""..current_range_start)
		else
			table.insert(ranges, current_range_start..delim..current_range_end)
		end
	end
	return ranges
end

local function render_month(year, month, start_time, end_time)
	local month_name = mw.language.getContentLanguage():formatDate("F", year.."-"..month.."-01", false)
	local start_day = (year == start_time.year and month == start_time.month and start_time.day or 1)
	local end_day = (year == end_time.year and month == end_time.month and end_time.day or 31)
	local existing_days = {}
	for day=start_day, end_day do
		local title = mw.title.makeTitle("Wiktionary", "Word of the day/"..year.."/"..month_name.." "..day)
		if title.id ~= 0 then
			table.insert(existing_days, day)
		end
	end
	if #existing_days == 0 then
		return nil
	end
	local day_ranges = rangify(existing_days, "–")
	local month_link = "]"
	return month_link .. " " .. listify(day_ranges, ", ")
end

local function render_months(year, start_time, end_time)
	local list = {}
	local start_month = (year == start_time.year and start_time.month or 1)
	local end_month = (year == end_time.year and end_time.month or 12)
	for month=start_month, end_month do
	  table.insert(list, render_month(year, month, start_time, end_time))
	end
	return list
end

local function render_year(year, start_time, end_time)
	local month_list = listify(render_months(year, start_time, end_time), "; ")
	if month_list == nil then
		return ""
	end
	return "* " .. year .. " – " .. month_list .. "\n"
end

local function render(start_time, end_time)
	local wikitext = ""
	for year=start_time.year, end_time.year do
		wikitext = wikitext .. render_year(year, start_time, end_time)
	end
	return wikitext
end

function export.status()
	return render(os.date("*t"), os.date("*t", os.time() + 365*86400))
end

return export