Jump to content

Module:Weekly site information: Difference between revisions

Dat Hack3r (talk | contribs)
m Dat Hack3r moved page Module:Weekly Briefing Release to Module:Weekly site information without leaving a redirect: This module now implements {{Weekly site information}} in its entirety, so it should take on its name.
Dat Hack3r (talk | contribs)
Removed padding from date numbers (i.e., Dec 1 instead of Dec 01) and added error handling.
Line 1: Line 1:
local p = {}
local p = {}
local mw_error = require('Module:Error').error


local first_date = os.time{year=2024, month=9, day=8}
local first_date = os.time{year=2024, month=9, day=8}
Line 13: Line 15:
end_date.day = end_date.day - (end_date.wday - 1) + offset * 7
end_date.day = end_date.day - (end_date.wday - 1) + offset * 7


local start_date = os.time{year=end_date.year, month=end_date.month, day=end_date.day - 7}
local start_date = os.date("*t", os.time{year=end_date.year, month=end_date.month, day=end_date.day - 7})


return "Weekly Briefing Release " .. release_num .. " " .. os.date("%b %d", start_date) .. " - " .. os.date("%b %d", os.time(end_date))
return string.format("Weekly Briefing Release %d %s - %s",
release_num,
os.date("%b %d", os.time(start_date)):gsub(" 0", " "),
os.date("%b %d", os.time(end_date)):gsub(" 0", " ")
)
end
end


Line 23: Line 29:
else
else
for i=1,-math.floor(diff / 7),-1 do
for i=1,-math.floor(diff / 7),-1 do
mw.log(release(i))
if mw.title.new(release(i), "").exists then
if mw.title.new(release(i), "").exists then
return "[[" .. release(i) .. "|" .. link_text .. "]]"
return "[[" .. release(i) .. "|" .. link_text .. "]]"
end
end
end
end
return mw_error{"No Releases found. Something has gone very, very wrong."}
end
end
end
end


function p.main(frame)
function p.main(frame)
mw.log(frame:getParent().args[1])
local link_text = frame:getParent().args[1] or "Weekly Site Information"
local link_text = frame:getParent().args[1] or "Weekly Site Information"
local offset = tonumber(frame:getParent().args['offset'])
local offset = tonumber(frame:getParent().args['offset'])