Module:Sandbox/Dat Hack3r

From Our World of Text Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Sandbox/Dat Hack3r/doc

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