Module:Sandbox/Dat Hack3r: Difference between revisions
Jump to navigation
Jump to search
Dat Hack3r (talk | contribs) (This is a sandbox, who cares about the edit summary?) |
Dat Hack3r (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- Function to calculate the week number based on | -- Function to calculate the previous week's number based on the current date | ||
function p. | function p.lastReleaseNumber(frame) | ||
-- Define the start date of Week 1 | -- Define the start date of Week 1 | ||
local week1Start = os.time{year=2024, month=9, day=8} | local week1Start = os.time{year=2024, month=9, day=8} | ||
-- Convert the | -- Convert the input date from the frame to a time object | ||
local | local year = tonumber(frame.args.year) | ||
local month = tonumber(frame.args.month) | |||
local day = tonumber(frame.args.day) | |||
local currentDate = os.time{year=year, month=month, day=day} | |||
-- Calculate the difference in days from the start of Week 1 | -- Calculate the difference in days from the start of Week 1 to the current date | ||
local daysDifference = os.difftime( | local daysDifference = os.difftime(currentDate, week1Start) / (24 * 60 * 60) | ||
-- Calculate the week number | -- Calculate the current week number | ||
local currentWeek = math.floor(daysDifference / 7) + 1 | local currentWeek = math.floor(daysDifference / 7) + 1 | ||
-- Calculate the previous week number | -- Calculate the previous week number, ensuring it does not go below 1 | ||
local previousWeek = math.max(currentWeek - 1, 1) | local previousWeek = math.max(currentWeek - 1, 1) | ||
return | return previousWeek | ||
end | end | ||
return p | return p |
Revision as of 12:33, 13 November 2024
Documentation for this module may be created at Module:Sandbox/Dat Hack3r/doc
local p = {}
-- Function to calculate the previous week's number based on the current date
function p.lastReleaseNumber(frame)
-- Define the start date of Week 1
local week1Start = os.time{year=2024, month=9, day=8}
-- Convert the input date from the frame to a time object
local year = tonumber(frame.args.year)
local month = tonumber(frame.args.month)
local day = tonumber(frame.args.day)
local currentDate = os.time{year=year, month=month, day=day}
-- Calculate the difference in days from the start of Week 1 to the current date
local daysDifference = os.difftime(currentDate, week1Start) / (24 * 60 * 60)
-- Calculate the current week number
local currentWeek = math.floor(daysDifference / 7) + 1
-- Calculate the previous week number, ensuring it does not go below 1
local previousWeek = math.max(currentWeek - 1, 1)
return previousWeek
end
return p