Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:Kalendar/podstranka

require('Module:No globals')

local p = {}
local root = {}

local function addRow(row)
	table.insert(root, row)
end

local function getMonthName(month)
	return ({"leden","únor","březen","duben","květen","červen","červenec","srpen","září","říjen","listopad","prosinec"})[month]
end

local function isLeapYear(year)
	return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)
end

local function getDaysInMonth(month, year)
	return (month == 2 and isLeapYear(year) and 29)
		or ("\31\28\31\30\31\30\31\31\30\31\30\31"):byte(month)
end

local function getValue(args, key, default)
	local value = args[key]
	if value and value ~= '' then
		return value
	else
		return default
	end
end

function p.main(frame)
	local year = tonumber(frame.args.year)
	local month = tonumber(frame.args.month)
	local markDay = tonumber(frame.args.markDay) or 0

	local firstWeekday = tonumber(os.date("%w",os.time{year=year, month=month, day=1}))
	local monthName = getMonthName(month)
	local daysInMonth = getDaysInMonth(month, year)

	addRow('{| class="wst-kalendar"')
	addRow('|+ ' .. monthName ..' ' .. year )
	addRow('|-')
	addRow('! Po')
	addRow('! Út')
	addRow('! St')
	addRow('! Čt')
	addRow('! Pá')
	addRow('! So')
	addRow('! Ne')
	addRow('|-')

	for i = 1, (firstWeekday - 1) % 7 do
		addRow("|")
	end

	for i = 1, daysInMonth do
		local text = "| [[/" .. i .. ". " .. monthName .. "|" .. i .. "]]"
		if i == markDay then
			addRow('| class="wst-kalendar-den" ' .. text)
		else
			addRow(text)
		end
		if (i + firstWeekday - 1) % 7 == 0 then
			addRow("|-")
		end
	end

	addRow('|}')

	return table.concat(root, '\n')
end

return p