Module:One page calendar explained

require ('strict');local getArgs = require ('Module:Arguments').getArgs

-- sequence to hold abbreviated month names where first-of-month is on daylocal first_day_t =

local subheader_rows_t =

local week_day_names_t =

local row_format_str = '|| %s || %s || %s || %s || %s || %s || %s '; -- format string for the three subheader rows

local weekday_rows_fmt_t =

local caption_fmt = 'Calendar for year with 1 %s on a %s'; -- first %s is 'January' in local language; second %s is day name in local language

--main|year=}}supported parameters are: |year= the year for which this calendar is rendered; defaults to current year |lang-tag= language in which this calendar is rendered; defaults to wiki's own language |table-style= css style string suitable for use in an html style="" attribute; no quotes; defaults to empty string |caption= a caption that replaces the default caption

local function main (frame) local args_t = getArgs (frame); args_t['table-style'] = (args_t['table-style'] and ' style="' .. args_t['table-style'] .. '"') or ; -- if not set, empty string for concatenation; applies to whole table

local lang_object; if args_t['lang-tag'] then lang_object = mw.language.new (args_t['lang-tag']); -- get a language object for the language specified by |lang-tag= else lang_object = mw.language.getContentLanguage; -- get a language object for the local wiki language end if not week_day_names_t.sun_t[1] then -- if empty auto fill; otherwise assume that tables have been filled manually at a local wiki for i, day in ipairs do -- sequence values are used as indexes into week_day_names_t local long = lang_object:formatDate ('l', '2022-05-0' .. i); -- 2022-05-01 is known to be a Sunday; calculate day names for the rest of the week local abbreviated = lang_object:formatDate ('D', '2022-05-0' .. i); -- 2022-05-01 is known to be a Sun; calculate abbreviated day names for the rest of the week week_day_names_t[day][1] = abbreviated; -- abbreviated day names: Sun, Mon, etc in local wiki language week_day_names_t[day][2] = long; -- full day names: Sunday, Monday, etc in local wiki language week_day_names_t[day][3] = table.concat ; end end local year = (args_t.year and args_t.year) or lang_object:formatDate ('Y'); -- get year from |year=; current year else TODO: get year from article title? local jan_1_day = lang_object:formatDate ('l', year .. '-01-01'); -- get day name for day on which 1 January occurs; for day name in table caption local jan_1_mon = lang_object:formatDate ('F', year .. '-01-01'); -- i18n: get month name for -01-01; for month name in table caption

for m=1, 12 do local month_abbr = lang_object:formatDate ('M', year .. '-' .. m); -- get abbreviated month name local day_number = lang_object:formatDate ('w', year .. '-' .. m .. '-01') + 1; -- returns a value 0-6; +1 offset makes 1-7 to index into first_day_t lua sequence table.insert (first_day_t[day_number], month_abbr); -- add abbreviated month name to appropriate day number sequence end

for row=1, 3 do -- for each of the three 'month' subheader rows for day=1, 7 do -- and for each day of the week in that row if first_day_t[day][row] then -- if first of the month occurs on table.insert (subheader_rows_t[row], first_day_t[day][row]); -- insert abreviated month name else table.insert (subheader_rows_t[row], ); -- insert empty string else end end end

local out_t = ; -- components of the output go here

local caption = (args_t.caption and args_t.caption) or string.format (caption_fmt, jan_1_mon, jan_1_day); table.insert (out_t, '

year= or current year

for i, row_t in ipairs (subheader_rows_t) do -- for each of the three 'month' subheader rows if 1

i then -- first of these rows has rowspan and colspan styling table.insert (out_t, string.format ('

Date ' .. row_format_str, row_t[1], row_t[2], row_t[3], row_t[4], row_t[5], row_t[6], row_t[7])); else -- the others have no styling table.insert (out_t, string.format (row_format_str, row_t[1], row_t[2], row_t[3], row_t[4], row_t[5], row_t[6], row_t[7])); end end -- append static day numbers and weekday rows table.insert (out_t, string.format (weekday_rows_fmt_t[1], week_day_names_t.sun_t[3], week_day_names_t.mon_t[3], week_day_names_t.tue_t[3], week_day_names_t.wed_t[3], week_day_names_t.thu_t[3], week_day_names_t.fri_t[3], week_day_names_t.sat_t[3])); table.insert (out_t, string.format (weekday_rows_fmt_t[2], week_day_names_t.mon_t[3], week_day_names_t.tue_t[1], week_day_names_t.wed_t[1], week_day_names_t.thu_t[1], week_day_names_t.fri_t[1], week_day_names_t.sat_t[1], week_day_names_t.sun_t[1])); table.insert (out_t, string.format (weekday_rows_fmt_t[3], week_day_names_t.tue_t[3], week_day_names_t.wed_t[1], week_day_names_t.thu_t[1], week_day_names_t.fri_t[1], week_day_names_t.sat_t[1], week_day_names_t.sun_t[1], week_day_names_t.mon_t[1])); table.insert (out_t, string.format (weekday_rows_fmt_t[4], week_day_names_t.wed_t[3], week_day_names_t.thu_t[1], week_day_names_t.fri_t[1], week_day_names_t.sat_t[1], week_day_names_t.sun_t[1], week_day_names_t.mon_t[1], week_day_names_t.tue_t[1])); table.insert (out_t, string.format (weekday_rows_fmt_t[5], week_day_names_t.thu_t[3], week_day_names_t.fri_t[1], week_day_names_t.sat_t[1], week_day_names_t.sun_t[1], week_day_names_t.mon_t[1], week_day_names_t.tue_t[1], week_day_names_t.wed_t[1])); table.insert (out_t, string.format (weekday_rows_fmt_t[6], week_day_names_t.fri_t[3], week_day_names_t.sat_t[1], week_day_names_t.sun_t[1], week_day_names_t.mon_t[1], week_day_names_t.tue_t[1], week_day_names_t.wed_t[1], week_day_names_t.thu_t[1])); table.insert (out_t, string.format (weekday_rows_fmt_t[7], week_day_names_t.sat_t[3], week_day_names_t.sun_t[1], week_day_names_t.mon_t[1], week_day_names_t.tue_t[1], week_day_names_t.wed_t[1], week_day_names_t.thu_t[1], week_day_names_t.fri_t[1]));

table.insert (out_t, '

'); -- close wikitable return table.concat (out_t, '\n|-\n'); -- make a big string and done

end

----------------------------< E X P O R T S >----------------------------------------------------------------

return