Module:DayCalc: Difference between revisions

Fixing up the get_next_tuesday logic and made it use an offset so that the date calculation uses Pacific Standard Time
(Copied over from myndmess:Module:DayCalc)
 
(Fixing up the get_next_tuesday logic and made it use an offset so that the date calculation uses Pacific Standard Time)
 
(3 intermediate revisions by the same user not shown)
Line 5:
function p.get_next_tuesday(frame)
local isodate = frame.args.isodate
local current_timepst_tzoffset = os.time0 - ( 8 * 60 * 60 )
local current_time = os.time() + pst_tzoffset
local current_day_of_week = tonumber(os.date("%w", current_time))
local days_until_tuesday = (9 - current_day_of_week) % 7
local next_tuesday_time = current_time + days_until_tuesday * 8640024 --* 8640060 seconds* in a day60
local retval="UNDEFINED"
local next_tuesday_time = current_time + days_until_tuesday * 86400 -- 86400 seconds in a day
 
if isodate == "true" and current_day_of_week == 2 then
ifretval isodate == os.date("true%Y-%m-%d", thencurrent_time)
elseif current_day_of_week == 2 then
retval return= os.date("%Y-B %m-d, %dY", current_time)
else
elseif isodate == true then
return os.date("%B %d, %Y", current_time)
retval return= os.date("%Y-%m-%d", next_tuesday_time)
end
else
if isodateretval == os.date("true%B %d, %Y", thennext_tuesday_time)
return os.date("%Y-%m-%d", next_tuesday_time)
else
return os.date("%B %d, %Y", next_tuesday_time)
end
end
return retval
end
 
 
function p.get_first_coming_tuesday_of_month(frame)
local isodate = frame.args.isodate
local current_timecurrent_year = tonumber(os.timedate("%Y"))
local current_yearcurrent_month = tonumber(os.date("%Ym", current_time))
local current_monthcurrent_datenum = tonumber(os.date("%me", current_time))
local first_day_day_of_weekday_of_week = tonumber(os.date("%w", first_day_of_month))
 
local first_day_of_month = os.time({ year = current_year, month = current_month, day = 1, hour = 0, min = 0, sec = 0 })
local first_tuesday_day
local first_day_day_of_week = tonumber(os.date("%w", first_day_of_month))
 
if next_monthcurrent_datenum > 127 then
local days_until_first_tuesday = (9 - first_day_day_of_week) % 7
current_month = current_month + 1
local first_tuesday_time = first_day_of_month + days_until_first_tuesday * 86400
if current_month > 12 then
next_monthcurrent_month = 1
if current_time > first_tuesday_time then
local next_month current_year = current_monthcurrent_year + 1
local next_year = current_year
if next_month > 12 then
next_month = 1
next_year = next_year + 1
end
elseif current_datenum <= 7 and day_of_week == 2 then
if isodate == "true" then
return os.date("%Y-%m-%d", os.time({ year = next_year, month = next_month, day = 1, hour = 0, min = 0, sec = 0 }) + days_until_first_tuesday * 86400)
else
return os.date("%B %e, %Y", os.time({ year = next_year, month = next_month, day = 1, hour = 0, min = 0, sec = 0 }) + days_until_first_tuesday * 86400)
end
elseend
 
for day = 1, 7 do
local first_day_of_monthday_time = os.time({ year = current_year, month = current_month, day = 1day, hour = 0, min = 0, sec = 0 })
local day_of_week = tonumber(os.date("%w", day_time))
if day_of_week == 2 then -- Tuesday
first_tuesday_day = day
end break
elseend
end
 
if first_tuesday_day then
local first_tuesday_time = os.time({ year = current_year, month = current_month, day = first_tuesday_day, hour = 0, min = 0, sec = 0 })
 
if isodate == "true" then
return os.date("%Y-%m-%d", first_tuesday_time)
Line 56 ⟶ 65:
return os.date("%B %e, %Y", first_tuesday_time)
end
else
return "Unable to calculate first Tuesday of the month."
end
end