ಮಾಡ್ಯೂಲ್:Custom-calendar
ಗೋಚರ
Documentation for this module may be created at ಮಾಡ್ಯೂಲ್:Custom-calendar/doc
local p = {}
-- Table for Kannada numerals
local kannadaNumbers = {
["0"] = "೦", ["1"] = "೧", ["2"] = "೨", ["3"] = "೩", ["4"] = "೪",
["5"] = "೫", ["6"] = "೬", ["7"] = "೭", ["8"] = "೮", ["9"] = "೯"
}
-- Function to convert English numbers to Kannada
local function convertToKannada(number)
return tostring(number):gsub("%d", function(digit)
return kannadaNumbers[digit] or digit
end)
end
function p.build(frame)
local month = tonumber(frame.args.month) or 1
local year = tonumber(frame.args.year) or 2024
local language = frame.args.language or "en"
-- Get the first day of the month
local firstDay = os.time{year = year, month = month, day = 1}
local dayOfWeek = tonumber(os.date("%w", firstDay)) -- 0=Sunday, 6=Saturday
local daysInMonth = tonumber(os.date("%d", os.time{year = year, month = month + 1, day = 0}))
-- Generate rows
local calendar = {}
local row = {}
-- Fill in empty days before the first day
for _ = 1, dayOfWeek do
table.insert(row, '<td style="border: 1px solid #ccc;"> </td>')
end
-- Fill in the actual days of the month
for day = 1, daysInMonth do
local dayStr = tostring(day)
if language == "kannada" then
dayStr = convertToKannada(day)
end
table.insert(row, '<td style="border: 1px solid #ccc;">' .. dayStr .. '</td>')
-- Start a new row if Saturday (6th column) is reached
if (#row % 7 == 0) then
table.insert(calendar, '<tr>' .. table.concat(row, "") .. '</tr>')
row = {}
end
end
-- Fill in the remaining cells of the last row
while (#row < 7) do
table.insert(row, '<td style="border: 1px solid #ccc;"> </td>')
end
table.insert(calendar, '<tr>' .. table.concat(row, "") .. '</tr>')
-- Return the complete table rows
return table.concat(calendar, "\n")
end
return p