Module:Weekly site information: Difference between revisions

From Our World of Text Wiki
Jump to navigation Jump to search
m (Dat Hack3r moved page Module:Last Weekly Briefing Release number to Module:Weekly Briefing Release without leaving a redirect: This module name is more appropriate for planned functionality.)
(Test successful, deploying new version.)
Line 1: Line 1:
local p = {}
local p = {}


function p.main(frame)
local function release(prev)
    -- Define the start date of Week 1
     local first_date = os.time{year=2024, month=9, day=8}
     local week1Start = os.time{year=2024, month=9, day=8}
    local curr_date = os.date("*t", os.time())
    if prev == true then
    curr_date.day = curr_date.day - 7
    end
    curr_date = os.time(curr_date)


     -- Get current date
     local diff = os.difftime(curr_date, first_date) / (24 * 60 * 60)
     local currentDate = os.time()
     local release_num = math.floor(diff / 7)


    -- Calculate the difference in days from the start of Week 1 to the current date
     local end_date = os.date("*t", curr_date - (diff % 7) * 24 * 60 * 60)
     local daysDifference = os.difftime(currentDate, week1Start) / (24 * 60 * 60)
    end_date.day = end_date.day - (end_date.wday - 1)


     -- Return the last Weekly Briefing Release
     local start_date = os.time{year=end_date.year, month=end_date.month, day=end_date.day - 7}
    return math.floor(daysDifference / 7)
 
    return release_num .. " " .. os.date("%b %d", start_date) .. " - " .. os.date("%b %d", os.time(end_date))
end
 
function p.most_recent()
return release(false)
end
 
function p.previous()
return release(true)
end
end


return p
return p

Revision as of 21:06, 27 November 2024

local p = {}

local function release(prev)
    local first_date = os.time{year=2024, month=9, day=8}
    local curr_date = os.date("*t", os.time())
    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 release_num = math.floor(diff / 7)

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

    return release_num .. " " .. os.date("%b %d", start_date) .. " - " .. os.date("%b %d", os.time(end_date))
end

function p.most_recent()
	return release(false)
end

function p.previous()
	return release(true)
end

return p