Modul:Calendar
Aspect
Modulul implementează {{Calendar}}
local du = require('Modul:DateUtils')
local getArgs = require('Modul:Arguments').getArgs
local months = {[1] = 'ianuarie', [2] = 'februarie', [3] = 'martie', [4] = 'aprilie',
[5] = 'mai', [6] = 'iunie', [7] = 'iulie', [8] = 'august',
[9] = 'septembrie', [10] = 'octombrie', [11] = 'noiembrie',
[12] = 'decembrie'}
local dates = require('Modul:Dates')
p = {}
p.fromArgs = function(year, month, args)
month = tonumber(month)
local length = dates._days_in_month(year, month, 'Gregorian')
local wd = os.date("%u", os.time{year=year, month=month, day=1}) - 1
local current_day = 1
local month_s = months[month]
local month_obj = mw.title.new(month_s .. " " .. year)
local month_link = "'''[[" .. month_s .. " " .. year .. "]]'''"
if not month_obj.exists then month_link = "'''[[" .. month_s .. "]] [[" .. year .. "]]'''" end
local next_month = month + 1
local next_year = year
if next_month > #months then
next_month = 1
next_year = year + 1
end
local next_month_link = "[[" .. months[next_month] .. " " .. next_year .. "|►]]"
local prev_month = month - 1
local prev_year = year
if prev_month < 1 then
prev_month = 12
prev_year = year - 1
end
local prev_month_link = "[[" .. months[prev_month] .. " " .. prev_year .. "|◄]]"
first_header = prev_month_link .. " " .. month_link .. " " .. next_month_link
root = mw.html.create('table')
root:addClass('toccolours')
:css('float',args["float"] or "right")
:css('margin-left','1em')
:css('text-align','center')
:css('width',args["lățime"] or '100px')
root:tag('tr')
:tag('td')
:attr('colspan','7')
:css('background',args["culoare"] or "#ccccff")
:wikitext(first_header)
root:tag('tr')
:css('background',args["culoare2"] or "#ccccff")
:tag('td')
:attr('width','14%')
:wikitext("'''L'''")
:tag('td')
:attr('width','14%')
:wikitext("'''Ma'''")
:tag('td')
:attr('width','14%')
:wikitext("'''Mi'''")
:tag('td')
:attr('width','14%')
:wikitext("'''J'''")
:tag('td')
:attr('width','14%')
:wikitext("'''V'''")
:tag('td')
:attr('width','14%')
:wikitext("'''S'''")
:tag('td')
:attr('width','14%')
:wikitext("'''D'''")
--first week
if current_day == 1 then
week = mw.html.create('tr')
mw.logObject(wd,"weekday")
if wd > 0 then
week:tag('td')
:attr('colspan',wd)
:wikitext(' ')
end
for i=wd,6,1 do
week:tag('td')
:wikitext("[[" .. current_day .. " " .. month_s .. "|" .. current_day .. "]]")
current_day = current_day + 1
end
root:wikitext(tostring(week))
end
mw.logObject(current_day,"cd")
-- full weeks
while current_day + 6 <= length do
week = mw.html.create('tr')
for i=0,6,1 do
week:tag('td')
:wikitext("[[" .. current_day .. " " .. month_s .. "|" .. current_day .. "]]")
current_day = current_day + 1
end
root:wikitext(tostring(week))
end
-- last week
week = mw.html.create('tr')
for i=current_day,length,1 do
week:tag('td')
:wikitext("[[" .. current_day .. " " .. month_s .. "|" .. current_day .. "]]")
current_day = current_day + 1
end
root:wikitext(tostring(week))
return tostring(root)
end
p.fromFrame = function(frame)
local args = getArgs(frame)
local year = args[1] or args["an"] or args["year"] or os.date("%Y")
local month = args[2] or args["lună"] or args["month"] or os.date("%m")
return p.fromArgs(year, month, args)
end
return p