Jump to content

Module:Weekly site information: Difference between revisions

Dat Hack3r (talk | contribs)
Updated functionality and implementation.
Dat Hack3r (talk | contribs)
Can now return the title of a Release given its release number; for use in other modules.
 
(2 intermediate revisions by the same user not shown)
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 5: Line 7:
local diff = os.difftime(curr_date, first_date) / (24 * 60 * 60)
local diff = os.difftime(curr_date, first_date) / (24 * 60 * 60)


local function release(offset)
function p._release(offset, release_num)
offset = offset or 0
offset = offset or 0
if release_num then
offset = release_num - math.floor(diff / 7)
end


local release_num = math.floor(diff / 7) + offset
release_num = release_num or (math.floor(diff / 7) + offset)


local end_date = os.date("*t", curr_date - (diff % 7) * 24 * 60 * 60)
local end_date = os.date("*t", curr_date - (diff % 7) * 24 * 60 * 60)
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


function p._main(link_text, offset)
function p._main(link_text, offset)
if offset then
if offset then
return "[[" .. release(offset) .. "|" .. link_text .. "]]"
return "[[" .. p._release(offset) .. "|" .. link_text .. "]]"
else
else
for i=1,-math.floor(diff / 7),-1 do
for i=1,-math.floor(diff / 7),-1 do
if mw.title.new(release(i), "").exists then
mw.log(p._release(i))
return "[[" .. release(i) .. "|" .. link_text .. "]]"
if mw.title.new(p._release(i), "").exists then
return "[[" .. p._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'])