Module:Weekly site information: Difference between revisions

From Our World of Text Wiki
Jump to navigation Jump to search
(Test successful, deploying new version.)
(Updated functionality and implementation.)
Line 1: Line 1:
local p = {}
local p = {}


local function release(prev)
local first_date = os.time{year=2024, month=9, day=8}
    local first_date = os.time{year=2024, month=9, day=8}
local curr_date = os.time()
    local curr_date = os.date("*t", os.time())
local diff = os.difftime(curr_date, first_date) / (24 * 60 * 60)
    if prev == true then
    curr_date.day = curr_date.day - 7
    end
    curr_date = os.time(curr_date)


    local diff = os.difftime(curr_date, first_date) / (24 * 60 * 60)
local function release(offset)
    local release_num = math.floor(diff / 7)
offset = offset or 0


    local end_date = os.date("*t", curr_date - (diff % 7) * 24 * 60 * 60)
local release_num = math.floor(diff / 7) + offset
    end_date.day = end_date.day - (end_date.wday - 1)


    local start_date = os.time{year=end_date.year, month=end_date.month, day=end_date.day - 7}
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


    return release_num .. " " .. os.date("%b %d", start_date) .. " - " .. os.date("%b %d", os.time(end_date))
local start_date = 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))
end
end


function p.most_recent()
function p._main(link_text, offset)
return release(false)
if offset then
return "[[" .. release(offset) .. "|" .. link_text .. "]]"
else
for i=1,-math.floor(diff / 7),-1 do
if mw.title.new(release(i), "").exists then
return "[[" .. release(i) .. "|" .. link_text .. "]]"
end
end
end
end
end


function p.previous()
function p.main(frame)
return release(true)
mw.log(frame:getParent().args[1])
local link_text = frame:getParent().args[1] or "Weekly Site Information"
local offset = tonumber(frame:getParent().args['offset'])
return p._main(link_text, offset)
end
end


return p
return p

Revision as of 15:54, 28 November 2024

local p = {}

local first_date = os.time{year=2024, month=9, day=8}
local curr_date = os.time()
local diff = os.difftime(curr_date, first_date) / (24 * 60 * 60)

local function release(offset)
	offset = offset or 0

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

	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

	local start_date = 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))
end

function p._main(link_text, offset)
	if offset then
		return "[[" .. release(offset) .. "|" .. link_text .. "]]"
	else
		for i=1,-math.floor(diff / 7),-1 do
			if mw.title.new(release(i), "").exists then
				return "[[" .. release(i) .. "|" .. link_text .. "]]"
			end
		end
	end
end

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

return p