local activity = {}
function activity.days (year)
if year % 4 ~= 0 or year % 100 == 0 and year % 400 ~= 0 then
return 365
end
return 366
end
function activity.this_year ()
return os.date"%Y"
end
function activity.first_week_day (year)
year = year or activity.this_year()
return os.date("*t", os.time{year=year, month=1, day=1}).wday
end
function activity.generate_table (year)
year = year or activity.this_year()
local function spot ()
return [[
]]
end
local function day (level)
return ([[ | ]]):format(level)
end
local function cell (exists)
if not exists then
return spot
end
return day
end
local function row (weekday, first, last)
first = cell(first)
last = cell(last)
local row = ([[ | %s]]):format(weekday)
row = row .. first(math.random(0, 4))
for _=1,51 do
row = row .. day(math.random(0, 4))
end
row = row .. last(math.random(0, 4)) .. "\n"
return row
end
local rows = ""
local weekdays = {"", "Mon", "", "Wed", "", "Fri", ""}
local start_from = activity.first_week_day(year)
local end_at = (start_from + activity.days(year) - 1) % 7
for index, weekday in pairs(weekdays) do
rows = rows .. row(weekday, index >= start_from, index <= end_at)
end
return [["
end
return activity
|