Module:DayCalc: Difference between revisions

Content added Content deleted
(Simplifying, but still kludged. Will need to fix properly later)
(Fixing up the get_next_tuesday logic and made it use an offset so that the date calculation uses Pacific Standard Time)
 
Line 5: Line 5:
function p.get_next_tuesday(frame)
function p.get_next_tuesday(frame)
local isodate = frame.args.isodate
local isodate = frame.args.isodate
local current_time = os.time()
local pst_tzoffset = 0 - ( 8 * 60 * 60 )
local current_time = os.time() + pst_tzoffset
local current_day_of_week = tonumber(os.date("%w", current_time))
local current_day_of_week = tonumber(os.date("%w", current_time))
local days_until_tuesday = (7 - current_day_of_week) % 7
local days_until_tuesday = (9 - current_day_of_week) % 7
local next_tuesday_time = current_time + days_until_tuesday * 86400 -- 86400 seconds in a day
local next_tuesday_time = current_time + days_until_tuesday * 24 * 60 * 60
local retval="UNDEFINED"
local retval="UNDEFINED"


if isodate == "true" then
if isodate == "true" and current_day_of_week == 2 then
retval=os.date("%Y-%m-%d", current_time)
retval = os.date("%Y-%m-%d", current_time)
elseif current_day_of_week == 2 then
retval="2023-12-19"
retval = os.date("%B %d, %Y", current_time)
elseif isodate == true then
retval = os.date("%Y-%m-%d", next_tuesday_time)
else
else
retval=os.date("%B %d, %Y", current_time)
retval = os.date("%B %d, %Y", next_tuesday_time)
retval="December 19, 2023"
end
end
return retval
return retval